__class__
Normally the __class__
attribute of an object will return its type. For a mock object with a spec
, __class__
returns the spec class instead. This allows mock objects to pass isinstance()
tests for the object they are replacing / masquerading as:
>>> mock = Mock(spec=3) >>> isinstance(mock, int) True
__class__
is assignable to, this allows a mock to pass an isinstance()
check without forcing you to use a spec:
>>> mock = Mock() >>> mock.__class__ = dict >>> isinstance(mock, dict) True
Please login to continue.