Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def __init__(self):
self._patches = [] # list of mock._patch objects
self.patch = self._Patcher(self._patches)

def resetall(self):
"""
Call reset_mock() on all patchers started by this fixture.
"""
for p in self._patches:
p.get_original()[0].reset_mock()

def stopall(self):
"""
Stop all patchers started by this fixture. Can be safely called multiple
Expand Down
15 changes: 15 additions & 0 deletions test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def test_mocker_has_mock_class_as_attribute_for_instantiation():
assert isinstance(mocker.Mock(), mock_module.Mock)


def test_mocker_resetall(mocker):
listdir = mocker.patch('os.listdir')
open = mocker.patch('os.open')

listdir("/tmp")
open("/tmp/foo.txt")
listdir.assert_called_once_with("/tmp")
open.assert_called_once_with("/tmp/foo.txt")

mocker.resetall()

assert not listdir.called
assert not open.called


def test_mocker_stub(mocker):
def foo(on_something):
on_something('foo', 'bar')
Expand Down