Mock(2.0.0).assert_has_calls() raise AssertionError in two same calls
See original GitHub issuehello, i use Mock (2.0.0) in python2.7,and found this issue.
Example: test.py
from mock import Mock,call
class BB(object):
def __init__(self):pass
def print_b(self):pass
def print_bb(self,tsk_id):pass
bMock = Mock(return_value=Mock(spec=BB))
bMock().print_bb(20)
bMock().assert_has_calls([call.print_bb(20)])
python test.py Traceback (most recent call last): File “test.py”, line 11, in <module> bMock().assert_has_calls([call.print_bb(20)]) File “/usr/lib/python2.7/site-packages/mock/mock.py”, line 969, in assert_has_calls ), cause) File “/usr/lib/python2.7/site-packages/six.py”, line 718, in raise_from raise value AssertionError: Calls not found. Expected: [call.print_bb(20)] Actual: [call.print_bb(20)]
print expected in mock.py assert_has_calls() [TypeError(‘too many positional arguments’,)]
issue in cpython: http://bugs.python.org/issue26752
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Python's assert_has_calls throws AssertionError that calls ...
I'm getting two of them: one mock_producer in the test class and a second mocked producer called myproducer (the name I used in...
Read more >Issue 43371: Mock.assert_has_calls works strange
When I call Mock.assert_has_calls with any_order=False it checks that expected calls are the same calls as performed on mock and raise an ...
Read more >python's assert_has_calls throws assertionerror ... - splunktool
I'm getting two of them: one mock_producer in the test class and a second ... in raise_from raise value AssertionError: Calls not found....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Here is another example that triggers this issue:
Test run output:
What I’ve found is that
mock_class._call_matcherattempts to bind thebar(2, 3)call tomock_class._spec_signature, but that’s the signature of theFooclass (Foo.__init__(self, a), single positional argument), not that of theFoo.barmethod (Foo.bar(self, a, b), two positional arguments), thus it returnsTypeError('too many positional arguments')instead. If I drop the spec from the mock, the assertion succeeds, so it is not really a case of calls not matching but obviously a conflict with the spec itself.I love it how it took two years and a half to close this issue with “report it upstream instead” 🙄