python
runtime_error
ai_generated
true
AssertionError:assert {'a': 1, 'b': 2} == {'a': 1, 'b': 3} 省略了 1 个相同项,使用 -vv 显示 不同项:
AssertionError: assert {'a': 1, 'b': 2} == {'a': 1, 'b': 3} Omitting 1 identical items, use -vv to show Differing items:
ID: python/pytest-assertion-introspection-noqa
80%修复率
87%置信度
0证据数
2024-04-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
断言差异默认被截断;开发者认为差异缺失,实际上 -vv 会显示它。有时真正的错误是类型不匹配(1 与 '1')。
English
The assertion diff is truncated by default; developers think the diff is missing when actually -vv would show it. Sometimes the real bug is a type mismatch (1 vs '1').
解决方案
-
95% 成功率
pytest -vv tests/test_x.py::test_dict
-
90% 成功率
# pytest.ini [pytest] addopts = -vv --showlocals
无效尝试
常见但无效的做法:
-
70% 失败
Adds noise; the real fix is enabling verbose diff.
-
75% 失败
unittest diff is also truncated by default.
-
80% 失败
Only shows the message, not the structured diff.