diff -r ac27d979078a Lib/unittest/mock.py --- a/Lib/unittest/mock.py Thu Sep 05 00:23:08 2013 +0200 +++ b/Lib/unittest/mock.py Mon Sep 09 11:39:05 2013 +0200 @@ -495,8 +495,12 @@ side_effect = property(__get_side_effect, __set_side_effect) - def reset_mock(self): + def reset_mock(self, visited=[]): "Restore the mock object to its initial state." + if id(self) in visited: + return + visited.append(id(self)) + self.called = False self.call_args = None self.call_count = 0 @@ -507,11 +511,11 @@ 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): diff -r ac27d979078a Misc/NEWS --- a/Misc/NEWS Thu Sep 05 00:23:08 2013 +0200 +++ b/Misc/NEWS Mon Sep 09 11:39:05 2013 +0200 @@ -178,6 +178,9 @@ - Issue #8860: Fixed rounding in timedelta constructor. +- Issue #18622: Fixed the infinite recursion in `reset_mock()`. Solved by tracking + a set of visited ids. + Tests -----