This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients Claudiu.Popa, and, cjw296, iforapsy, kushal.das, mariocj89, michael.foord, xtreak
Date 2019-07-10.18:38:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562783898.96.0.841175071474.issue21478@roundup.psfhosted.org>
In-reply-to
Content
> 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
History
Date User Action Args
2019-07-10 18:38:19xtreaksetrecipients: + xtreak, cjw296, michael.foord, Claudiu.Popa, kushal.das, and, mariocj89, iforapsy
2019-07-10 18:38:18xtreaksetmessageid: <1562783898.96.0.841175071474.issue21478@roundup.psfhosted.org>
2019-07-10 18:38:18xtreaklinkissue21478 messages
2019-07-10 18:38:18xtreakcreate