Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

> 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

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue21478>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to