This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cheryl.sabella
Recipients Erik Byström, cheryl.sabella, docs@python, mariocj89
Date 2019-01-25.13:45:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548423900.23.0.759804680211.issue30548@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-01-25 13:45:01cheryl.sabellasetrecipients: + cheryl.sabella, docs@python, mariocj89, Erik Byström
2019-01-25 13:45:00cheryl.sabellasetmessageid: <1548423900.23.0.759804680211.issue30548@roundup.psfhosted.org>
2019-01-25 13:45:00cheryl.sabellalinkissue30548 messages
2019-01-25 13:45:00cheryl.sabellacreate