mirror of
https://github.com/python/cpython.git
synced 2024-11-27 20:04:41 +08:00
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
This commit is contained in:
commit
a7282c0ff7
@ -523,8 +523,14 @@ class NonCallableMock(Base):
|
|||||||
side_effect = property(__get_side_effect, __set_side_effect)
|
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."
|
"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.called = False
|
||||||
self.call_args = None
|
self.call_args = None
|
||||||
self.call_count = 0
|
self.call_count = 0
|
||||||
@ -535,11 +541,11 @@ class NonCallableMock(Base):
|
|||||||
for child in self._mock_children.values():
|
for child in self._mock_children.values():
|
||||||
if isinstance(child, _SpecState):
|
if isinstance(child, _SpecState):
|
||||||
continue
|
continue
|
||||||
child.reset_mock()
|
child.reset_mock(visited)
|
||||||
|
|
||||||
ret = self._mock_return_value
|
ret = self._mock_return_value
|
||||||
if _is_instance_mock(ret) and ret is not self:
|
if _is_instance_mock(ret) and ret is not self:
|
||||||
ret.reset_mock()
|
ret.reset_mock(visited)
|
||||||
|
|
||||||
|
|
||||||
def configure_mock(self, **kwargs):
|
def configure_mock(self, **kwargs):
|
||||||
|
@ -246,6 +246,9 @@ class MockTest(unittest.TestCase):
|
|||||||
# used to cause recursion
|
# used to cause recursion
|
||||||
mock.reset_mock()
|
mock.reset_mock()
|
||||||
|
|
||||||
|
def test_reset_mock_on_mock_open_issue_18622(self):
|
||||||
|
a = mock.mock_open()
|
||||||
|
a.reset_mock()
|
||||||
|
|
||||||
def test_call(self):
|
def test_call(self):
|
||||||
mock = Mock()
|
mock = Mock()
|
||||||
|
@ -1583,3 +1583,5 @@ Gennadiy Zlobin
|
|||||||
Doug Zongker
|
Doug Zongker
|
||||||
Peter Åstrand
|
Peter Åstrand
|
||||||
Ignacio Rossi
|
Ignacio Rossi
|
||||||
|
Laurent De Buyst
|
||||||
|
Nicola Palumbo
|
||||||
|
@ -13,6 +13,9 @@ Core and Builtins
|
|||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
|
||||||
|
Patch from Nicola Palumbo and Laurent De Buyst.
|
||||||
|
|
||||||
- Issue #24426: Fast searching optimization in regular expressions now works
|
- Issue #24426: Fast searching optimization in regular expressions now works
|
||||||
for patterns that starts with capturing groups. Fast searching optimization
|
for patterns that starts with capturing groups. Fast searching optimization
|
||||||
now can't be disabled at compile time.
|
now can't be disabled at compile time.
|
||||||
|
Loading…
Reference in New Issue
Block a user