
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-09-20 10:27 byfelixonmars, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| fix_mock_call_ne.patch | aplummer,2016-02-08 11:01 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg251162 -(view) | Author: Felix Yan (felixonmars)* | Date: 2015-09-20 10:27 | |
Since Python 3.5.0 mock.MagicMock() object seems not matched by mock.ANY. This behavior looks weird and breaks tests of boto.Minimized example:In Python 3.4.3:>>> from unittest import mock>>> m = mock.MagicMock()>>> m(mock.MagicMock())<MagicMock name='mock()' id='139728217270704'>>>> m.assert_called_with(mock.ANY)>>>In Python 3.5.0:>>> from unittest import mock>>> m = mock.MagicMock()>>> m(mock.MagicMock())<MagicMock name='mock()' id='140093484276536'>>>> m.assert_called_with(mock.ANY)Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.5/unittest/mock.py", line 792, in assert_called_with raise AssertionError(_error_message()) from causeAssertionError: Expected call: mock(<ANY>)Actual call: mock(<MagicMock id='140093520206872'>) | |||
| msg259811 -(view) | Author: Andrew Plummer (aplummer)* | Date: 2016-02-08 00:02 | |
I've had a look and I think this could be because the class _Call (also in unittest.mock) has lost its __ne__ method between 3.4 and 3.5.Comparehttps://hg.python.org/cpython/file/v3.4.4/Lib/unittest/mock.py#l2010withhttps://hg.python.org/cpython/file/v3.5.1/Lib/unittest/mock.py#l2028This leads me to this changeset:https://hg.python.org/cpython/rev/3603bae63c13My failing test:from unittest import mockcall1 = mock.call(mock.MagicMock())call2 = mock.call(mock.ANY)assert call1 == call2assert not (call1 != call2)This passes in 3.4 but fails in 3.5, but fails on the second assert, not the first. So they are equal, but they're not not-equal. I've added this as a test and reinstated __ne__ in my patch. | |||
| msg259814 -(view) | Author: Berker Peksag (berker.peksag)*![]() | Date: 2016-02-08 04:36 | |
Looks like _Call is a subclass of tuple. Checks in the test could be written as "self.assertIs(a == b, True)". | |||
| msg259822 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2016-02-08 06:54 | |
It would be better to use just default implementation: __ne__ = object.__ne__Interesting that while call1 == call2 is True, call2 == call1 is False. But this is different issue. | |||
| msg259835 -(view) | Author: Andrew Plummer (aplummer)* | Date: 2016-02-08 11:00 | |
Have added a new diff to just use the default __ne__ implementation rather than tuple's.Have also added a test that targets exactly the reported issue. | |||
| msg262538 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2016-03-27 21:28 | |
New changesetdcd3b078ab84 by Berker Peksag in branch '3.5':Issue#25195: Fix a regression in mock.MagicMockhttps://hg.python.org/cpython/rev/dcd3b078ab84New changeset880d609b6664 by Berker Peksag in branch 'default':Issue#25195: Fix a regression in mock.MagicMockhttps://hg.python.org/cpython/rev/880d609b6664 | |||
| msg262539 -(view) | Author: Berker Peksag (berker.peksag)*![]() | Date: 2016-03-27 21:29 | |
Thanks! | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:21 | admin | set | github: 69382 |
| 2016-03-27 21:30:10 | berker.peksag | set | keywords: +patch |
| 2016-03-27 21:29:41 | berker.peksag | set | status: open -> closed messages: +msg262539 keywords: +3.5regression, -patch resolution: fixed stage: patch review -> resolved |
| 2016-03-27 21:28:48 | python-dev | set | nosy: +python-dev messages: +msg262538 |
| 2016-02-08 11:01:34 | aplummer | set | files: -fix_mock_call_ne.patch |
| 2016-02-08 11:01:19 | aplummer | set | files: +fix_mock_call_ne.patch |
| 2016-02-08 11:01:06 | aplummer | set | files: -test_assert_called_with_any.diff |
| 2016-02-08 11:00:02 | aplummer | set | files: +test_assert_called_with_any.diff messages: +msg259835 |
| 2016-02-08 06:54:02 | serhiy.storchaka | set | messages: +msg259822 |
| 2016-02-08 04:36:19 | berker.peksag | set | versions: + Python 3.6 nosy: +berker.peksag messages: +msg259814 stage: patch review |
| 2016-02-08 04:10:21 | berker.peksag | set | nosy: +serhiy.storchaka |
| 2016-02-08 00:02:58 | aplummer | set | files: +fix_mock_call_ne.patch nosy: +aplummer messages: +msg259811 keywords: +patch |
| 2016-02-07 05:36:42 | ned.deily | set | nosy: +michael.foord |
| 2015-09-20 10:27:28 | felixonmars | set | type: behavior |
| 2015-09-20 10:27:20 | felixonmars | create | |