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) *  |
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) *  |
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) *  |
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) *  |
Date: 2017-01-20 17:37 |
Proposed patch fixes comparing MagicMock with ANY. |
|
|
msg285925 - (view) |
Author: Berker Peksag (berker.peksag) *  |
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)  |
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) *  |
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. |
|
|