xxxxxxxxxx
>>> real = SomeClass()
>>> real.method = MagicMock(name='method')
>>> real.method(3, 4, 5, key='value')
<MagicMock name='method()' id='...'>
xxxxxxxxxx
>>> real = ProductionClass()
>>> mock = Mock()
>>> real.closer(mock)
>>> mock.close.assert_called_with()
xxxxxxxxxx
>>> class ProductionClass:
def method(self):
self.something(1, 2, 3)
def something(self, a, b, c):
pass
>>> real = ProductionClass()
>>> real.something = MagicMock()
>>> real.method()
>>> real.something.assert_called_once_with(1, 2, 3)
xxxxxxxxxx
>>> class ProductionClass:
def closer(self, something):
something.close()