diff options
| author | Mario Corchero <mariocj89@gmail.com> | 2019-04-30 19:56:36 +0100 |
|---|---|---|
| committer | Chris Withers <chris@withers.org> | 2019-04-30 19:56:36 +0100 |
| commit | 0df635c7f8aa69e56a092bd4f142f0f164741ab2 (patch) | |
| tree | fc549b19dcdcfc45a85512165ac3e05eec428e9a /Lib/unittest/test/testmock/testmock.py | |
| parent | d537ab0ff9767ef024f26246899728f0116b1ec3 (diff) | |
| download | cpython-git-0df635c7f8aa69e56a092bd4f142f0f164741ab2.tar.gz | |
Don't report deleted attributes in __dir__ (GH#10148)
When an attribute is deleted from a Mock, a sentinel is added rather
than just deleting the attribute. This commit checks for such sentinels
when returning the child mocks in the __dir__ method as users won't
expect deleted attributes to appear when performing dir(mock).
Diffstat (limited to 'Lib/unittest/test/testmock/testmock.py')
| -rw-r--r-- | Lib/unittest/test/testmock/testmock.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py index bdaebbe66b..0e7e4a1d8c 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -885,6 +885,15 @@ class MockTest(unittest.TestCase): patcher.stop() + def test_dir_does_not_include_deleted_attributes(self): + mock = Mock() + mock.child.return_value = 1 + + self.assertIn('child', dir(mock)) + del mock.child + self.assertNotIn('child', dir(mock)) + + def test_configure_mock(self): mock = Mock(foo='bar') self.assertEqual(mock.foo, 'bar') |
