You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2013-02-02.23:29:01.035>created_at=<Date2013-01-22.12:44:11.909>labels= ['type-feature', 'library']
title="mock could be smarter and inspect the spec's signature"updated_at=<Date2013-02-02.23:29:01.034>user='https://github.com/pitrou'
>>> deff(a, b): pass
>>> mock = Mock(spec=f)
>>> mock(1, 2)
<Mock name='mock()' id='140654219634288'>
>>> mock.assert_called_with(1, 2)
>>> mock.assert_called_with(a=1, b=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/antoine/cpython/default/Lib/unittest/mock.py", line 726, in assert_called_with
AssertionError: Expected call: mock(b=2, a=1)
Actual call: mock(1, 2)
This means your test assertions will depend unduly on some code style details (whether some function is called using positional or keyword arguments).
Note: if this is fixed, it should be made to work with method calls too.
Wow, impressive work Antoine - thanks. I am a little concerned that this relies on Python 3 only features of inspect, and *in fact* relies on bug fixes in Python 3.4 to work. That means it would be hard / impossible for the backport "mock" to have the new feature. That may be solveable (there is a backport of function signatures which mock could use for example).