python
type_error
ai_generated
true
断言错误:断言 <Mock name='mock()' id='140735234567890'> == 5
AssertionError: assert <Mock name='mock()' id='140735234567890'> == 5
ID: python/pytest-assert-repr-failure
80%修复率
88%置信度
0证据数
2025-11-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
根因分析
测试将模拟对象与值进行比较,可能是因为模拟对象未设置返回值,因此默认返回另一个模拟对象。
English
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.
解决方案
-
95% 成功率 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% 成功率 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.
无效尝试
常见但无效的做法:
-
Comparing the mock to itself using `is`
70% 失败
This does not test the actual behavior; it only checks identity.
-
Setting return_value to a string like '5'
50% 失败
This changes the type; the test expects an integer 5.