python runtime_error ai_generated true

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

ID: python/unittest-mock-assert_called_with-failure

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
0Evidence
2024-08-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

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

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 30% fail

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