Title: Mock(2.0.0).assert_has_calls() raise AssertionError in two same calls
Type: behavior Stage:
Components: Tests Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: guboi72, jekin000, jwdevel, michael.foord, rbcollins
Priority: normal Keywords:

Created on 2016-04-14 07:43 by jekin000, last changed 2017-11-16 17:50 by guboi72.

File name Uploaded Description Edit jekin000, 2016-04-14 07:43
Messages (4)
msg263375 - (view) Author: James (jekin000) * Date: 2016-04-14 07:43
>>> import mock
>>> print mock.__version__

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

Traceback (most recent call last):
  File "", line 11, in <module>
  File "/usr/lib/python2.7/site-packages/mock/", line 969, in assert_has_calls
    ), cause)
  File "/usr/lib/python2.7/site-packages/", line 718, in raise_from
    raise value
AssertionError: Calls not found.
Expected: [call.print_bb(20)]
Actual: [call.print_bb(20)]

print expected in assert_has_calls()

result is:
[TypeError('too many positional arguments',)]
msg287728 - (view) Author: John W. (jwdevel) Date: 2017-02-13 21:54
This also seems to apply to unittest.mock in Python3.4.

I described my similar issue on SO:

It seems like it may be the same issue described here.

For reference, this is my repro case:

from unittest.mock import patch, call

    class Foo:
        def __init__(self):
        def my_method(self, value):
    def test_foo():
        with patch('test.Foo', autospec=True) as MockFoo:
            m = MockFoo()
            MockFoo.assert_has_calls([call(), call().my_method(123)])

It fails with:

    E               AssertionError: Calls not found.
    E               Expected: [call(), call().my_method(123)]
    E               Actual:   [call(), call().my_method(123)]

Which seems nonsensical to me.

Removing the `value` parameter and the `123` arguments in the test makes it pass(!)
msg288222 - (view) Author: John W. (jwdevel) Date: 2017-02-20 17:48
This got a little discussion over at

The current evidence seem to indicate this is indeed a bug in the implementation of assert_has_calls.
msg306390 - (view) Author: Guillaume Boily (guboi72) Date: 2017-11-16 17:50
As pointed here:,

this issue is related to the method assert_has_calls or probably any calls that use the method _call_matcher to match calls. Given that you mock a class and spec it, since we always bind to the _spec_signature (e.g. the constructor signature), when it is a method call then it bind() throws a TypeError looking like `missing a require argument`. A possible solution would be to include method signatures into the spec.
Date User Action Args
2017-11-16 17:50:57guboi72setversions: + Python 3.6, - Python 2.7, Python 3.4
nosy: + guboi72

messages: + msg306390

components: + Tests
2017-02-20 17:48:35jwdevelsetmessages: + msg288222
2017-02-13 21:54:01jwdevelsetnosy: + jwdevel

messages: + msg287728
versions: + Python 3.4
2016-04-14 11:46:05SilentGhostsetnosy: + michael.foord
2016-04-14 07:43:24jekin000create