python runtime_error ai_generated true

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

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

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 70% fail

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

  2. 80% fail

    This only checks the call count, not the arguments.