Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify resetall to work with patch object #241

Merged
merged 3 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/pytest_mock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def resetall(
:param bool side_effect: Reset the side_effect of mocks.
"""
for m in self._mocks:
m.reset_mock(return_value=return_value, side_effect=side_effect)

if isinstance(m, self.Mock):
m.reset_mock(return_value=return_value, side_effect=side_effect)
continue

m.reset_mock()

def stopall(self) -> None:
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ def bar(self, x):
assert spy.spy_return == 30
assert spy.spy_exception is None

# Testing spy can still be reset.
mocker.resetall()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a working test case. If you add this line to the previous version 3.6.0 then it triggers the error.

with pytest.raises(ValueError):
Foo().bar(0)
assert spy.spy_return is None
Expand Down