python runtime_error ai_generated true

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

ID: python/unittest-assertcount-equal-error

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.12 active

Root Cause

使用 assert_called_with 检查 mock 调用时,参数不匹配

generic

中文

使用 assert_called_with 检查 mock 调用时,参数不匹配

Workarounds

  1. 90% success
    print(mock.call_args_list) 然后修正预期
  2. 80% success
    mock.assert_any_call(1)

Dead Ends

Common approaches that don't work:

  1. 60% fail

    只检查调用次数,不检查参数

  2. 30% fail

    可能不符合测试意图