python
type_error
ai_generated
true
AssertionError: assert <Mock name='mock()' id='140735234567890'> == 5
ID: python/pytest-assert-repr-failure
80%Fix Rate
88%Confidence
0Evidence
2025-11-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
Root Cause
A test is comparing a mock object to a value, likely because the mock was not set up to return a value, so it returns another mock by default.
generic中文
测试将模拟对象与值进行比较,可能是因为模拟对象未设置返回值,因此默认返回另一个模拟对象。
Workarounds
-
95% success Set the mock's return_value to the expected integer value
mock = MagicMock(return_value=5) result = mock() assert result == 5 Or: mock.return_value = 5
-
85% success Ensure the code under test is calling the mock correctly
Debug to see if the mock is being called. If not, the test may be comparing the mock object itself instead of its return value.
Dead Ends
Common approaches that don't work:
-
Comparing the mock to itself using `is`
70% fail
This does not test the actual behavior; it only checks identity.
-
Setting return_value to a string like '5'
50% fail
This changes the type; the test expects an integer 5.