You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2020-01-25.15:46:39.649>created_at=<Date2019-11-27.19:59:26.401>labels= ['type-bug', 'library', '3.9']
title='unittest.mock.Mock.reset_mocks does not pass all arguments to its children'updated_at=<Date2020-01-25.15:46:39.648>user='https://github.com/vegarsti'
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
Thanks Vegard for the report. The docs say "Child mocks and the return value mock (if any) are reset as well." so it makes sense to me to reset the return_value and side_effect of children. But as mentioned in the PR it's a behaviour change that someone might be dependent on and can go on 3.9 . If we are not going ahead with the change then we can clarify the same in the docs and ask the user to reset mock recursively on their own so that it avoids confusion.