When the unittest.mock.Mock object was called, I can check the values โโof the arguments with the exact signature of the call:
from unittest.mock import Mock m = Mock()
Verification of another signature with the same values โโwill fail. For example, if we check with 'baz' as a positional argument instead of a named argument, the statement will fail:
m.assert_called_once_with('foo', 'baz')
He must. If the function replaced by m was
def actual_fu(foo, bar):
then the calls will be equivalent, but if it was
def a_different_actual_fu(foo, *args, bar='some default'):
then the calls will not be equivalent. Mock does not know the actual signature of the function, so it cannot rely on the equivalence that we would have in the first case.
Is there a way to check the values โโof call arguments that are agnostic about whether they were passed positionally or as keyword arguments , letting Mock (or an auxiliary statement function or the like) know about the actual function is replaced by the layout?
A Mock object can be notified of an object that it replaces (which can be a function or method), with an optional spec argument or with autospeccing , but they serve a different purpose (limiting which calls to allow for the layout) and do not affect post-fact checking .
das-g source share