python runtime_error ai_generated true

AssertionError: Expected 'foo' to be called with (1,) but was called with (2,)

ID: python/unittest-mock-side-effect-assertion-error

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

The mock's call arguments don't match the expected arguments, often due to incorrect input or mock configuration.

generic

中文

mock 的调用参数与预期参数不匹配,通常是由于输入错误或 mock 配置错误。

Workarounds

  1. 90% success
    print(mock.call_args)
    assert mock.call_args == call(1,)
  2. 85% success
    mock.assert_any_call(1)

Dead Ends

Common approaches that don't work:

  1. 80% fail

    This hides the real bug in the code.

  2. 90% fail

    It still fails if arguments don't match.