summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-07-14 23:42:28 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-07-14 23:42:28 (GMT)
commitb37f43f94b693468d8b3b9dfc84b1930c52a1b61 (patch)
tree172fa92019a9728252f64417321ecb9fee36cef4 /Lib/unittest/mock.py
parentacb3a4d88bdee64096ed4f00c9d464b6b4513658 (diff)
downloadcpython-b37f43f94b693468d8b3b9dfc84b1930c52a1b61.zip
cpython-b37f43f94b693468d8b3b9dfc84b1930c52a1b61.tar.gz
cpython-b37f43f94b693468d8b3b9dfc84b1930c52a1b61.tar.bz2
- 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.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 1b1c9f4..c805726 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -519,8 +519,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
@@ -531,11 +537,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):