[issue39222] unittest.mock.Mock.parent is broken or undocumented

Karthikeyan Singaravelan report at bugs.python.org
Wed Jan 8 05:49:56 EST 2020


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

It's a similar situation to name argument conflict [0] except that it's parent here. You can use configure_mock or attribute setting to do the same thing like below. parent is discussed in the docs to indicate the attributes being children like "a" being the child of parent "m" as you have mentioned. Adding others for thoughts. 

>>> from unittest.mock import Mock
>>> m = Mock()
>>> m.configure_mock(parent=2)
>>> m.parent
2
>>> m.a()
<Mock name='mock.a()' id='4367727104'>

>>> m = Mock()
>>> m.parent = 2
>>> m.parent
2

[0] https://docs.python.org/3/library/unittest.mock.html#mock-names-and-the-name-attribute

----------
nosy: +cjw296, lisroach, mariocj89, michael.foord
versions: +Python 3.8, Python 3.9 -Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39222>
_______________________________________


More information about the Python-bugs-list mailing list