This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年09月20日 10:27 by felixonmars, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| 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 cause AssertionError: 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. Compare https://hg.python.org/cpython/file/v3.4.4/Lib/unittest/mock.py#l2010 with https://hg.python.org/cpython/file/v3.5.1/Lib/unittest/mock.py#l2028 This leads me to this changeset: https://hg.python.org/cpython/rev/3603bae63c13 My failing test: from unittest import mock call1 = mock.call(mock.MagicMock()) call2 = mock.call(mock.ANY) assert call1 == call2 assert 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) * (Python committer) | 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) * (Python committer) | 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) (Python triager) | Date: 2016年03月27日 21:28 | |
New changeset dcd3b078ab84 by Berker Peksag in branch '3.5': Issue #25195: Fix a regression in mock.MagicMock https://hg.python.org/cpython/rev/dcd3b078ab84 New changeset 880d609b6664 by Berker Peksag in branch 'default': Issue #25195: Fix a regression in mock.MagicMock https://hg.python.org/cpython/rev/880d609b6664 |
|||
| msg262539 - (view) | Author: Berker Peksag (berker.peksag) * (Python committer) | 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 | |