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 grzgrzgrz3
Recipients berker.peksag, ericvw, grzgrzgrz3, mariocj89, michael.foord, rbcollins, vstinner
Date 2017-06-21.18:45:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Existing mock implementation already has that feature. Mock attributes can be limited with `spec` attribute.

>>> inner_m = Mock(spec=["method2"], **{"method2.return_value": 1})
>>> m = Mock(spec=["method1"], **{"method1.return_value": inner_m})
>>> m.method1().method2()
>>> m.method1().attr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/unittest/", line 580, in __getattr__
    raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute 'attr'
Date User Action Args
2017-06-21 18:45:28grzgrzgrz3setrecipients: + grzgrzgrz3, vstinner, rbcollins, ericvw, michael.foord, berker.peksag, mariocj89
2017-06-21 18:45:28grzgrzgrz3setmessageid: <>
2017-06-21 18:45:28grzgrzgrz3linkissue30541 messages
2017-06-21 18:45:28grzgrzgrz3create