Author cbelu
Recipients cbelu
Date 2017-06-07.12:04:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1496837046.98.0.920527641247.issue30587@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-06-07 12:04:07cbelusetrecipients: + cbelu
2017-06-07 12:04:06cbelusetmessageid: <1496837046.98.0.920527641247.issue30587@psf.upfronthosting.co.za>
2017-06-07 12:04:06cbelulinkissue30587 messages
2017-06-07 12:04:06cbelucreate