python
runtime_error
ai_generated
true
AssertionError: 未找到预期调用。 预期: send_email('[email protected]') 实际: send_email('[email protected]', subject='Hello')
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%修复率
90%置信度
0证据数
2024-07-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
assert_called_with 要求参数完全匹配。如果实际调用包含额外的关键字参数,断言会失败。
English
assert_called_with requires an exact match of arguments. If the actual call includes additional keyword arguments, the assertion fails.
解决方案
-
95% 成功率
from unittest.mock import ANY mock.assert_called_with('[email protected]', subject=ANY) -
90% 成功率
mock.assert_called_with('[email protected]', subject='Hello')
无效尝试
常见但无效的做法:
-
80% 失败
This only checks the call count, not the arguments.
-
70% 失败
The extra arguments may be required for the function.