python runtime_error ai_generated true

AssertionError: expected call not found. Expected: send_email('[email protected]') Actual: send_email('[email protected]', subject='Hello')

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-07-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.12 active

Root Cause

assert_called_with requires an exact match of arguments. If the actual call includes additional keyword arguments, the assertion fails.

generic

中文

assert_called_with 要求参数完全匹配。如果实际调用包含额外的关键字参数,断言会失败。

Workarounds

  1. 95% success
    from unittest.mock import ANY
    mock.assert_called_with('[email protected]', subject=ANY)
  2. 90% success
    mock.assert_called_with('[email protected]', subject='Hello')

Dead Ends

Common approaches that don't work:

  1. 80% fail

    This only checks the call count, not the arguments.

  2. 70% fail

    The extra arguments may be required for the function.