python runtime_error ai_generated true

AssertionError: 未找到期望的调用。 期望: mock(1, 2, 3) 实际: mock(1, 2)

AssertionError: expected call not found. Expected: mock(1, 2, 3) Actual: mock(1, 2)

ID: python/unittest-mock-assert_called_with-failure

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

版本兼容性

版本状态引入弃用备注
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

根因分析

模拟对象被调用时使用了与预期不同的参数,通常是由于被测试代码中的错误或测试期望不正确。

English

The mock object was called with different arguments than expected, often due to a bug in the code under test or incorrect test expectations.

generic

解决方案

  1. 90% 成功率
    Debug the actual arguments by printing mock.call_args_list or using `print(mock.mock_calls)`
  2. 95% 成功率
    Update the test to match the correct arguments, or fix the production code to pass the expected arguments.

无效尝试

常见但无效的做法:

  1. 90% 失败

    This bypasses the argument validation, allowing incorrect calls to pass undetected.

  2. 30% 失败

    The call already happened; timing is not the issue. The arguments are simply wrong.