Issue 28735: Mock is equal to ANY but MagicMock is not (original) (raw)

Created on 2016-11-18 16:07 by rafael.fonseca, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
magicmock_eq.patch serhiy.storchaka,2017-01-20 17:37 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft,2017-03-31 16:36
Messages (8)
msg281135 - (view) Author: Rafael Jacinto Caricio da Fonseca (rafael.fonseca) Date: 2016-11-18 16:07
On Python 3.5.2 mock.Mock() is equal to mock.ANY, but mock.MagicMock() is not. Minimal example: In Python 3.5.2: >>> from unittest import mock >>> mock.Mock() == mock.ANY True >>> mock.ANY == mock.Mock() True >>> mock.MagicMock() == mock.ANY False >>> mock.ANY == mock.MagicMock() True
msg285908 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2017-01-20 14:25
From a checkout in last week. Python 3.7.0a0 (default:c163a76163f7, Jan 15 2017, 22:20:24) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from unittest import mock >>> mock.ANY == mock.Mock() True >>> mock.ANY == mock.MagicMock() True
msg285909 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-01-20 14:49
Kushal I think the OP is reporting `mock.MagicMock() == mock.ANY` is False while `mock.ANY == mock.MagicMock()` is True which is still the case in 3.7. A related issue is #25195. In that issue Serhiy has mentioned this behaviour(http://bugs.python.org/issue25195#msg259822).
msg285910 - (view) Author: Kushal Das (kushal.das) * (Python committer) Date: 2017-01-20 14:51
Now I understood, thanks. I think I should have more coffee before commenting on bugs :)
msg285918 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-20 17:37
Proposed patch fixes comparing MagicMock with ANY.
msg285925 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-01-20 23:13
Serhiy's patch looks pretty good to me, thanks! Also, thanks for the report, Rafael. I definitely forgot to fix this case after fixing issue 25195.
msg285966 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-21 21:17
New changeset 442eb26b1ca4 by Serhiy Storchaka in branch '3.5': Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. https://hg.python.org/cpython/rev/442eb26b1ca4 New changeset 4a38781538f7 by Serhiy Storchaka in branch '3.6': Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. https://hg.python.org/cpython/rev/4a38781538f7 New changeset 597515fcb343 by Serhiy Storchaka in branch 'default': Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. https://hg.python.org/cpython/rev/597515fcb343
msg285967 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-01-21 21:21
Thanks Berker. Maybe _Call.__eq__ also should return NotImplemented in some cases, but I don't have a demonstrating example.
History
Date User Action Args
2022-04-11 14:58:39 admin set github: 72921
2017-03-31 16:36:21 dstufft set pull_requests: + <pull%5Frequest952>
2017-01-21 21:21:01 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2017-01-21 21:17:52 python-dev set nosy: + python-devmessages: +
2017-01-20 23:13:59 berker.peksag set messages: + stage: patch review -> commit review
2017-01-20 17:37:55 serhiy.storchaka set files: + magicmock_eq.patchkeywords: + patchmessages: + stage: patch review
2017-01-20 14:51:39 kushal.das set messages: +
2017-01-20 14:49:07 xiang.zhang set nosy: + serhiy.storchaka, berker.peksag, xiang.zhangmessages: +
2017-01-20 14:25:16 kushal.das set nosy: + kushal.dasmessages: +
2016-11-18 21:02:43 SilentGhost set nosy: + michael.foordversions: + Python 3.6, Python 3.7
2016-11-18 16:07:14 rafael.fonseca create