(original) (raw)
from unittest import TestCase from unittest.mock import MagicMock class Foo: def __init__(self, x, y, z): self.x = x self.y = y self.z = z def __str__(self): return '{0}(x={1}, y={2}, z={3})'.format(self.__class__.__name__, self.x, self.y, self.z) def __repr__(self): return self.__str__() class Test(TestCase): def test1(self): bar = MagicMock() a = Foo('aa', 'bb', 'cc') bar.x(a) print(a) print(bar.x.call_args[0][0]) # first item of *args to call print(bar.x.call_args[0][0] is a) # currently prints True # if mock deepcopied, it would be False - the items returned # from mock_call would be frozen snapshots of what was passed # in, they wouldn't be the same object. # I don't think one way is much more surprising than the other. # The deepcopy behavior is also pretty unintuitive