Skip to content

Commit

Permalink
Merge pull request #88 from jdavisp3/fix-resetall-for-patch-dict
Browse files Browse the repository at this point in the history
Only reset actual mocks in resetall().
  • Loading branch information
nicoddemus authored Jul 17, 2017
2 parents 560bdbc + 0c9b300 commit 31077ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def _start_patch(self, mock_func, *args, **kwargs):
p = mock_func(*args, **kwargs)
mocked = p.start()
self._patches.append(p)
self._mocks.append(mocked)
if hasattr(mocked, 'reset_mock'):
self._mocks.append(mocked)
return mocked

def object(self, *args, **kwargs):
Expand Down
14 changes: 14 additions & 0 deletions test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def test_mock_patches(mock_fs, mocker, check_unix_fs_mocked):
mock_fs(mocker)
mocked_rm, mocked_ls = mock_fs(mocker)
check_unix_fs_mocked(mocked_rm, mocked_ls)
mocker.resetall()
mocker.stopall()


def test_mock_patch_dict(mocker):
Expand All @@ -100,6 +102,18 @@ def test_mock_patch_dict(mocker):
assert x == {'original': 1}


def test_mock_patch_dict_resetall(mocker):
"""
We can call resetall after patching a dict.
:param mock:
"""
x = {'original': 1}
mocker.patch.dict(x, values=[('new', 10)], clear=True)
assert x == {'new': 10}
mocker.resetall()
assert x == {'new': 10}


def test_deprecated_mock(mock, tmpdir):
"""
Use backward-compatibility-only mock fixture to ensure complete coverage.
Expand Down

0 comments on commit 31077ba

Please sign in to comment.