python
runtime_error
ai_generated
true
AssertionError: expected call not found. Expected: send_email('[email protected]') Actual: send_email('[email protected]', subject='Hello')
ID: python/pytest-mock-assert-called-with-any
80%Fix Rate
90%Confidence
0Evidence
2024-07-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
assert_called_with requires an exact match of arguments. If the actual call includes additional keyword arguments, the assertion fails.
generic中文
assert_called_with 要求参数完全匹配。如果实际调用包含额外的关键字参数,断言会失败。
Workarounds
-
95% success
from unittest.mock import ANY mock.assert_called_with('[email protected]', subject=ANY) -
90% success
mock.assert_called_with('[email protected]', subject='Hello')
Dead Ends
Common approaches that don't work:
-
80% fail
This only checks the call count, not the arguments.
-
70% fail
The extra arguments may be required for the function.