mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +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
|
@ -684,12 +684,14 @@ class NonCallableMock(Base):
|
|||
extras = self._mock_methods or []
|
||||
from_type = dir(type(self))
|
||||
from_dict = list(self.__dict__)
|
||||
from_child_mocks = [
|
||||
m_name for m_name, m_value in self._mock_children.items()
|
||||
if m_value is not _deleted]
|
||||
|
||||
from_type = [e for e in from_type if not e.startswith('_')]
|
||||
from_dict = [e for e in from_dict if not e.startswith('_') or
|
||||
_is_magic(e)]
|
||||
return sorted(set(extras + from_type + from_dict +
|
||||
list(self._mock_children)))
|
||||
return sorted(set(extras + from_type + from_dict + from_child_mocks))
|
||||
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue