if name in ('_mock_methods', '_mock_unsafe'):
raise AttributeError(name)
elif self._mock_methods is not None:
if name not in self._mock_methods or name in _all_magics:
but _mock_methods has not been set yet
because it gets set later in
class MagicMixin(object):
def __init__(self, *args, **kw):
self._mock_set_magics() # make magic work for kwargs in init
_safe_super(MagicMixin, self).__init__(*args, **kw)
self._mock_set_magics() # fix magic broken by upper level init
A user trying this in a test using mocks (in Python 2.7) reported crashes. She told me:
__mro__
fromMagicMock
when it gets constructed.MagicMock
has 2 base classes —MagicMixin and Mock
get_function_name_from_frame
callsgetattr(inst.__class__, '__mro__', None)
Mock
has__getattr__
method defined_mock_methods
:_mock_methods
has not been set yet