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 <1498070728.37.0.471526221035.issue30541@psf.upfronthosting.co.za>
In-reply-to
Content
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()
1
>>> 
>>> m.method1().attr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/unittest/mock.py", line 580, in __getattr__
    raise AttributeError("Mock object has no attribute %r" % name)
AttributeError: Mock object has no attribute 'attr'
History
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: <1498070728.37.0.471526221035.issue30541@psf.upfronthosting.co.za>
2017-06-21 18:45:28grzgrzgrz3linkissue30541 messages
2017-06-21 18:45:28grzgrzgrz3create