python
runtime_error
ai_generated
true
AssertionError: Expected mock to have been called once. Called 0 times.
ID: python/unittest-mock-return-value-not-asserted
80%Fix Rate
86%Confidence
0Evidence
2025-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The mock object's call count doesn't match the expected number, often due to incorrect patch target or logic.
generic中文
mock 对象的调用次数与预期不符,通常是由于补丁目标错误或逻辑错误。
Workarounds
-
90% success
with patch('module.function') as mock_func: call_code() mock_func.assert_called_once() -
85% success
mock_func.assert_any_call(arg1, arg2)
Dead Ends
Common approaches that don't work:
-
70% fail
This masks the real problem of why the code isn't calling the mock.
-
90% fail
The test becomes ineffective.