[New-bugs-announce] [issue25195] mock.ANY doesn't match mock.MagicMock() object

Felix Yan report at bugs.python.org
Sun Sep 20 12:27:20 CEST 2015


New submission from Felix Yan:

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'>)

----------
components: Library (Lib)
messages: 251162
nosy: felixonmars
priority: normal
severity: normal
status: open
title: mock.ANY doesn't match mock.MagicMock() object
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25195>
_______________________________________


More information about the New-bugs-announce mailing list