jsatt / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Invalid calls info when mock object called with updated dict as arg #237

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
>>> import mock
>>> m = mock.Mock()
>>> d = {'a':1}
>>> m(d)
>>> d['b'] = 2
>>> m(d)
>>> m.mock_calls
[call({'a': 1, 'b': 2}), call({'a': 1, 'b': 2})]

!!! but actual calls was [call({'a': 1}), call({'a': 1, 'b': 2})]

Original issue reported on code.google.com by a.a.appe...@gmail.com on 19 Aug 2014 at 2:38

GoogleCodeExporter commented 8 years ago
may be 
class CallableMixin(Base):
...

def _fixed_call(_mock_self, *args, **kwargs):
    # can't use self in-case a function / method we are mocking uses self
    # in the signature
    _mock_self._mock_check_sig(*args, **kwargs)
    return _mock_self._mock_call(*deepcopy(args), **deepcopy(kwargs))

Original comment by a.a.appe...@gmail.com on 19 Aug 2014 at 3:02

GoogleCodeExporter commented 8 years ago
Please see the documentation for "coping with mutable arguments".

Original comment by fuzzyman on 20 Aug 2014 at 6:18