diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2019-01-21 08:57:46 +0000 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-04-30 08:39:55 +0100 |
commit | 373301ed9cc7c964a45cb37f86f6c3696c190eb7 (patch) | |
tree | fa117bd9a080555f5f54840190321fb3cfc80331 /mock/tests/testmock.py | |
parent | 019b1b5fce34604b87a8046fa60fb400328f56f8 (diff) | |
download | mock-373301ed9cc7c964a45cb37f86f6c3696c190eb7.tar.gz |
bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)
* Allow repeated deletion of unittest.mock.Mock attributes
* fixup! Allow repeated deletion of unittest.mock.Mock attributes
* fixup! fixup! Allow repeated deletion of unittest.mock.Mock attributes
Backports: 222d303ade8aadf0adcae5190fac603bdcafe3f0
Signed-off-by: Chris Withers <chris@withers.org>
Diffstat (limited to 'mock/tests/testmock.py')
-rw-r--r-- | mock/tests/testmock.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mock/tests/testmock.py b/mock/tests/testmock.py index 8a8e7c3..b496a36 100644 --- a/mock/tests/testmock.py +++ b/mock/tests/testmock.py @@ -1834,6 +1834,33 @@ class MockTest(unittest.TestCase): self.assertRaises(AttributeError, getattr, mock, 'f') + def test_mock_does_not_raise_on_repeated_attribute_deletion(self): + # bpo-20239: Assigning and deleting twice an attribute raises. + for mock in (Mock(), MagicMock(), NonCallableMagicMock(), + NonCallableMock()): + mock.foo = 3 + self.assertTrue(hasattr(mock, 'foo')) + self.assertEqual(mock.foo, 3) + + del mock.foo + self.assertFalse(hasattr(mock, 'foo')) + + mock.foo = 4 + self.assertTrue(hasattr(mock, 'foo')) + self.assertEqual(mock.foo, 4) + + del mock.foo + self.assertFalse(hasattr(mock, 'foo')) + + + def test_mock_raises_when_deleting_nonexistent_attribute(self): + for mock in (Mock(), MagicMock(), NonCallableMagicMock(), + NonCallableMock()): + del mock.foo + with self.assertRaises(AttributeError): + del mock.foo + + 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 |