Message347631
> I think a possible fix is to move the inner mock extraction out to the attach_mock function as that function contains code to clear the mock's parent and name attributes. Downside is that that would make it fail on Dmitry's toy example.
Moving the inner mock check would cause the original report to fail. But the same logic can be copied to attach_mock so that name and parent for inner mock set in "mock" attribute is cleared. So _check_and_set_parent code path is hit the mock attribute without name and parent would behave as expected. Jack, would appreciate your review of the PR. I have added your report as a unittest along with directly using create_autospec with attach_mock that behaves like patch and autospec=True. I have also asserted that name is reset to child as per the docs at https://docs.python.org/3/library/unittest.mock.html#attaching-mocks-as-attributes
Thanks |
|
Date |
User |
Action |
Args |
2019-07-10 18:38:19 | xtreak | set | recipients:
+ xtreak, cjw296, michael.foord, Claudiu.Popa, kushal.das, and, mariocj89, iforapsy |
2019-07-10 18:38:18 | xtreak | set | messageid: <1562783898.96.0.841175071474.issue21478@roundup.psfhosted.org> |
2019-07-10 18:38:18 | xtreak | link | issue21478 messages |
2019-07-10 18:38:18 | xtreak | create | |
|