Skip to content

Commit c3e9aa1

Browse files
authored
Add resetall() arguments (#214)
1 parent 28ef007 commit c3e9aa1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/pytest_mock/plugin.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,15 @@ def __init__(self, config: Any) -> None:
6060
if hasattr(mock_module, "seal"):
6161
self.seal = mock_module.seal
6262

63-
def resetall(self) -> None:
64-
"""Call reset_mock() on all patchers started by this fixture."""
63+
def resetall(self, *, return_value: bool = False, side_effect: bool = False) -> None:
64+
"""
65+
Call reset_mock() on all patchers started by this fixture.
66+
67+
:param bool return_value: Reset the return_value of mocks.
68+
:param bool side_effect: Reset the side_effect of mocks.
69+
"""
6570
for m in self._mocks:
66-
m.reset_mock()
71+
m.reset_mock(return_value=return_value, side_effect=side_effect)
6772

6873
def stopall(self) -> None:
6974
"""

tests/test_pytest_mock.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,25 @@ def test_mocker_aliases(name: str, pytestconfig: Any) -> None:
177177

178178

179179
def test_mocker_resetall(mocker: MockerFixture) -> None:
180-
listdir = mocker.patch("os.listdir")
181-
open = mocker.patch("os.open")
180+
listdir = mocker.patch("os.listdir", return_value="foo")
181+
open = mocker.patch("os.open", side_effect=["bar", "baz"])
182182

183-
listdir("/tmp")
184-
open("/tmp/foo.txt")
183+
assert listdir("/tmp") == "foo"
184+
assert open("/tmp/foo.txt") == "bar"
185185
listdir.assert_called_once_with("/tmp")
186186
open.assert_called_once_with("/tmp/foo.txt")
187187

188188
mocker.resetall()
189189

190190
assert not listdir.called
191191
assert not open.called
192+
assert listdir.return_value == "foo"
193+
assert list(open.side_effect) == ["baz"]
194+
195+
mocker.resetall(return_value=True, side_effect=True)
196+
197+
assert isinstance(listdir.return_value, mocker.Mock)
198+
assert open.side_effect is None
192199

193200

194201
class TestMockerStub:

0 commit comments

Comments
 (0)