Message296573
| 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' |
|