Grzegorz Grzywacz added the comment: 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' ---------- nosy: +grzgrzgrz3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30541> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com