mocksafe.spy

mocksafe.spy(mocked: Any) MockCalls

This is used to capture the arguments that were passed when the given mocked was called, which is useful for making more detailed assertions on the contents.

The spy() function is actually an alias for that().

Both are just syntactic sugar to make your code flow more fluently, for example assert that(mock.foo).was_called versus args = spy(mock.foo).last_call.

Parameters:

mocked – a method on a mock object

Return type:

MockCalls

Example:
>>> spy(mock_random.random)
MockCalls[random;num_calls=0]
Example:
>>> spy(mock_random.random).was_not_called
True
Example:
>>> when(mock_random.random).any_call().then_return(0.123)
>>> mock_random.random()
0.123
>>> spy(mock_random.random).last_call
()
Example:
>>> when(mock_random.randint).any_call().then_return(5)
>>> mock_random.randint(0, 10)
5
>>> spy(mock_random.randint).last_call
(0, 10)