New submission from Claudiu Belu: Mock can accept a spec object / class as argument, making sure that accessing attributes that do not exist in the spec will cause an AttributeError to be raised, but there is no guarantee that the spec's methods signatures are respected in any way. This creates the possibility to have faulty code with passing unittests and assertions.
Steps to reproduce: >>> import mock >>> >>> class Something(object): ... def foo(self, a, b, c, d): ... pass ... >>> >>> m = mock.Mock(spec=Something) >>> m.foo() <Mock name='mock.foo()' id='140286904787240'> >>> # TypeError should be raised, but it isn't. ... >>> m.foo.assert_called_once_with() Expected behaviour: It should have raised a TypeError, since the method signature is: def meth(self, a, b, c, d): Actual behaviour: No error. ---------- components: Library (Lib) messages: 295335 nosy: cbelu priority: normal pull_requests: 2051 severity: normal status: open title: Mock with spec object does not ensure method call signatures type: behavior versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30587> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com