summaryrefslogtreecommitdiff
path: root/mock
diff options
context:
space:
mode:
Diffstat (limited to 'mock')
-rw-r--r--mock/mock.py2
-rw-r--r--mock/tests/testmock.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/mock/mock.py b/mock/mock.py
index cb0a577..a9b52ab 100644
--- a/mock/mock.py
+++ b/mock/mock.py
@@ -673,7 +673,7 @@ class NonCallableMock(Base):
self._mock_side_effect = None
for child in self._mock_children.values():
- if isinstance(child, _SpecState):
+ if isinstance(child, _SpecState) or child is _deleted:
continue
child.reset_mock(visited)
diff --git a/mock/tests/testmock.py b/mock/tests/testmock.py
index a61dff1..cda4124 100644
--- a/mock/tests/testmock.py
+++ b/mock/tests/testmock.py
@@ -1662,6 +1662,16 @@ class MockTest(unittest.TestCase):
self.assertRaises(AttributeError, getattr, mock, 'f')
+ def test_reset_mock_does_not_raise_on_attr_deletion(self):
+ # bpo-31177: reset_mock should not raise AttributeError when attributes
+ # were deleted in a mock instance
+ mock = Mock()
+ mock.child = True
+ del mock.child
+ mock.reset_mock()
+ self.assertFalse(hasattr(mock, 'child'))
+
+
def test_class_assignable(self):
for mock in Mock(), MagicMock():
self.assertNotIsInstance(mock, int)