Cheryl Sabella <cheryl.sabe...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue30548>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to