Skip to content

Commit 0c3dde0

Browse files
committed
fixup! Allow repeated deletion of unittest.mock.Mock attributes
1 parent 9eb6def commit 0c3dde0

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/unittest/test/testmock/testmock.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,14 @@ def test_mock_does_not_raise_on_repeated_attribute_deletion(self):
17901790
self.assertRaises(AttributeError, getattr, mock, 'foo')
17911791

17921792

1793+
def test_mock_raises_when_deleting_inexistent_attribute(self):
1794+
for mock in (Mock(), MagicMock(), NonCallableMagicMock(),
1795+
NonCallableMock()):
1796+
with self.assertRaises(AttributeError):
1797+
del mock.foo
1798+
del mock.foo
1799+
1800+
17931801
def test_reset_mock_does_not_raise_on_attr_deletion(self):
17941802
# bpo-31177: reset_mock should not raise AttributeError when attributes
17951803
# were deleted in a mock instance
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Allow repeated assignment deletion of ``unittest.mock.Mock`` attributes.
1+
Allow repeated assignment deletion of :class:`unittest.mock.Mock` attributes.
22
Patch by Pablo Galindo.

0 commit comments

Comments
 (0)