Karthikeyan Singaravelan <[email protected]> added the comment:
I have created a PR for this. My approach is that when
mock_thing.assert_has_calls(mock.call.method1(1, 2)) is made the
assert_has_calls is made against mock_thing whose spec_signature (constructor
signature) is always used. But there is _mock_children, a dictionary which has
signature for the methods. Thus method1 can be used as key for _mock_children
to get correct signature.
Where it gets tricky is that if there is a nested class whose method is called
like Foo.Bar.meth1 as below then the dictionary has only 'Bar' from which the
children has to be obtained to get meth1 signature like {'Foo': {'bar1':
signature}} and it's not stored with the key 'Foo.Bar.meth1' resulting in
iteration. There could be a better way or some edge case not covered so I have
opened up PR for review but if someone else has better approach then that would
be great too since this is a long standing issue resulting autospec needing to
be turned off.
class Foo:
class Bar:
def meth1(self, a): pass
This PR also solves the case at https://bugs.python.org/issue26752#msg287728.
There is a test failure caught by doctest for nested calls without spec and not
by unittest :) I have converted the doctest as a unittest.
----------
nosy: +cjw296, mariocj89, michael.foord
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36871>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com