You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Misleading introspection for assert_called_once, assert_any_call and similar assertions #640
pytest-mock adds introspection to failed mock assertions by comparing the mock's last call with the arguments given to the assertion. That doesn't fit two groups of assertions:
Assertions without arguments: assert_called_once, assert_not_called, assert_called, assert_awaited_once, assert_not_awaited, assert_awaited. The last call gets compared with the empty arguments of the assertion, which suggests an argument mismatch when the problem is the call count:
AssertionError: Expected 'mock' to have been called once. Called 2 times.
Calls: [call(1), call(2)].
pytest introspection follows:
Args:
assert (2,) == ()
assert_any_call / assert_any_await: these search all calls, but the introspection only compares the last one:
AssertionError: mock(4) call not found
pytest introspection follows:
Args:
assert (3,) == (4,)
Both reproduced on 3.16.1. Probably the simplest fix is to skip the introspection for these assertions and keep only the traceback hiding: no single call is "the" expected one.
Activity