mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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).
This commit is contained in:
parent
d537ab0ff9
commit
0df635c7f8
3 changed files with 15 additions and 2 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue