diff options
author | Robert Collins <rbtcollins@hp.com> | 2015-07-15 11:51:22 +1200 |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2015-07-15 11:51:22 +1200 |
commit | a7282c0ff7aff5ed00c0355e60fcbd34c45af910 (patch) | |
tree | 99f0c17a3e75f31339c1a5bdc81f1171dab00b01 /Lib/unittest/mock.py | |
parent | 34460827d6b1073fbc51c95006f63e3ad043eb4c (diff) | |
parent | 76d508b5d4bc8d69433956d6ee6309bbc31f3cf7 (diff) | |
download | cpython-git-a7282c0ff7aff5ed00c0355e60fcbd34c45af910.tar.gz |
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 191a175a41..944029bf00 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -523,8 +523,14 @@ class NonCallableMock(Base): side_effect = property(__get_side_effect, __set_side_effect) - def reset_mock(self): + def reset_mock(self, visited=None): "Restore the mock object to its initial state." + if visited is None: + visited = [] + if id(self) in visited: + return + visited.append(id(self)) + self.called = False self.call_args = None self.call_count = 0 @@ -535,11 +541,11 @@ class NonCallableMock(Base): for child in self._mock_children.values(): if isinstance(child, _SpecState): continue - child.reset_mock() + child.reset_mock(visited) ret = self._mock_return_value if _is_instance_mock(ret) and ret is not self: - ret.reset_mock() + ret.reset_mock(visited) def configure_mock(self, **kwargs): |