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 vegarsti
Recipients vegarsti
Date 2019-11-27.19:59:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574884766.44.0.780090732457.issue38932@roundup.psfhosted.org>
In-reply-to
Content
MagicMock, from unittest.mock, has a method reset_mock, which takes optional arguments return_value and side_effect, both with default values False.

In the body of reset_mock, reset_mock is again called on all the _mock_children of of the MagicMock object. However, here the arguments are not passed. This means that if you have a MagicMock object with children that are also mocked, and methods on these have been directly mocked, then it is not enough to call reset_mock on the parent object. A code example that demonstrates this follows below. Here, we could expect m to have been completely reset. But the final print statement shows that m.a() still returns 1.

```
from unittest.mock import MagicMock

m = MagicMock(a=MagicMock())
m.a.return_value = 1
m.reset_mock(return_value=True)
print(m.a())
```

Pertinent line in Github https://github.com/python/cpython/blob/dadff6f6610e03a9363c52ba9c49aa923984640a/Lib/unittest/mock.py#L601
History
Date User Action Args
2019-11-27 19:59:26vegarstisetrecipients: + vegarsti
2019-11-27 19:59:26vegarstisetmessageid: <1574884766.44.0.780090732457.issue38932@roundup.psfhosted.org>
2019-11-27 19:59:26vegarstilinkissue38932 messages
2019-11-27 19:59:26vegarsticreate