python runtime_error ai_generated true

AssertionError: 预期调用: my_func(1, 2) 实际调用: my_func(1, 2, 3)

AssertionError: Expected call: my_func(1, 2) Actual call: my_func(1, 2, 3)

ID: python/unittest-mock-assert-called-with-any

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-09-15首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

mock 被调用时带有未在 assert_called_with 中指定的额外参数。

English

The mock was called with additional arguments not specified in assert_called_with.

generic

解决方案

  1. 90% 成功率
    mock_func.assert_called_with(1, 2, mock.ANY)
  2. 95% 成功率
    print(mock_func.call_args) to see the actual arguments, then update the assertion or fix the code to call with the correct arguments.

无效尝试

常见但无效的做法:

  1. 70% 失败

    This may pass but does not verify that the function was called with the correct arguments; it just matches the current behavior.

  2. 80% 失败

    This only checks the call count, not the arguments.