Message296573
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' |
|
Date |
User |
Action |
Args |
2017-06-21 18:45:28 | grzgrzgrz3 | set | recipients:
+ grzgrzgrz3, vstinner, rbcollins, ericvw, michael.foord, berker.peksag, mariocj89 |
2017-06-21 18:45:28 | grzgrzgrz3 | set | messageid: <1498070728.37.0.471526221035.issue30541@psf.upfronthosting.co.za> |
2017-06-21 18:45:28 | grzgrzgrz3 | link | issue30541 messages |
2017-06-21 18:45:28 | grzgrzgrz3 | create | |
|