![](https://secure.gravatar.com/avatar/fa0f7819f1825f596b384c19aa7dcf33.jpg?s=120&d=mm&r=g)
Cheryl Sabella <cheryl.sabella@gmail.com> added the comment: Mario is right that this isn't a typo. Here's a code example to illustrate what he said:
class MyClass: ... a = 3 ... def foo(self): pass ... mock_class = create_autospec(MyClass) mock_class <MagicMock spec='MyClass' id='16678696'> mock_class() <NonCallableMagicMock name='mock()' spec='MyClass' id='16752016'> mock_class.foo <MagicMock name='mock.foo' spec='function' id='16751032'>
mock_instance = create_autospec(MyClass, instance=True) mock_instance <NonCallableMagicMock spec='MyClass' id='16757832'> mock_instance() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'NonCallableMagicMock' object is not callable mock_instance.foo <MagicMock name='mock.foo' spec='function' id='16750024'>
As per the docs, the instance object uses the class as the spec and it isn't callable, whereas the mock class is. Would adding this example to the docs help or would a different code example help make this less misleading? ---------- nosy: +cheryl.sabella _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue30548> _______________________________________