mocksafe.MockCalls

class mocksafe.MockCalls(call_recorder: CallRecorder)

Provides information about calls made to a mocked method.

This object returned by both mocksafe.that() and mocksafe.spy().

There’s no need to instantiate this class directly, just use those methods instead.

Example:
>>> assert that(mock_random.random).was_not_called
Example:
>>> spy(mock_random.random).was_not_called
True
>>> spy(mock_random.random).was_called
False
>>> spy(mock_random.random).num_calls
0
Example:
>>> spy(mock_random.random).last_call
Traceback (most recent call last):
 ...
ValueError: Mocked method random() was not called.
Example:
>>> when(mock_random.randint).any_call().then_return(5, 13)
>>> mock_random.randint(a=1, b=10)
5
>>> mock_random.randint(10, 20)
13
>>> assert that(mock_random.randint).last_call == (10, 20)
>>> assert that(mock_random.randint).nth_call(0) == ((), {"a":1, "b":10})
__init__(call_recorder: CallRecorder)

Methods

__setattr__(name, value, /)

Implement setattr(self, name, value).

nth_call(n)

Returns details of the Nth call made to the mocked method.

Attributes

all_calls

Returns a list of all calls made to the spied/mocked method.

last_call

Returns details of the last call made to the mocked method.

num_calls

Returns the number of calls made to the mocked method.

was_called

Return whether the mocked method was called at least once.

was_not_called

Return whether the mocked method was not called.