Message342245
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. |
|
Date |
User |
Action |
Args |
2019-05-12 08:16:24 | xtreak | set | recipients:
+ xtreak, gregory.p.smith, cjw296, michael.foord, mariocj89 |
2019-05-12 08:16:24 | xtreak | set | messageid: <1557648984.85.0.675121768268.issue36871@roundup.psfhosted.org> |
2019-05-12 08:16:24 | xtreak | link | issue36871 messages |
2019-05-12 08:16:24 | xtreak | create | |
|