python
runtime_error
ai_generated
true
断言错误:期望 'foo' 以 (1,) 被调用,但实际以 (2,) 被调用
AssertionError: Expected 'foo' to be called with (1,) but was called with (2,)
ID: python/unittest-mock-side-effect-assertion-error
80%修复率
85%置信度
0证据数
2025-08-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
mock 的调用参数与预期参数不匹配,通常是由于输入错误或 mock 配置错误。
English
The mock's call arguments don't match the expected arguments, often due to incorrect input or mock configuration.
解决方案
-
90% 成功率
print(mock.call_args) assert mock.call_args == call(1,)
-
85% 成功率
mock.assert_any_call(1)
无效尝试
常见但无效的做法:
-
80% 失败
This hides the real bug in the code.
-
90% 失败
It still fails if arguments don't match.