python
data_error
ai_generated
true
AssertionError: assert {'a': 1, 'b': 2, ...} == {'a': 1, 'b': 3, ...} 省略了 15 个相同项,使用 -vv 显示 不同项: {'b': 2} != {'b': 3}
AssertionError: assert {'a': 1, 'b': 2, ...} == {'a': 1, 'b': 3, ...} Omitting 15 identical items, use -vv to show Differing items: {'b': 2} != {'b': 3}
ID: python/pytest-assertion-dict-diff-truncated
80%修复率
82%置信度
0证据数
2024-10-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest 默认截断大型字典/列表差异;实际分歧隐藏在省略项中,使 CI 日志中的失败难以诊断。
English
pytest truncates large dict/list diffs by default; the actual divergence is hidden among omitted items, making the failure hard to diagnose in CI logs.
解决方案
-
90% 成功率
Raise verbosity: pytest -vv tests/test_config.py::test_merge # or set in config # [tool.pytest.ini_options] # addopts = "-vv"
-
85% 成功率
Or compute a minimal diff explicitly: from deepdiff import DeepDiff diff = DeepDiff(expected, actual, ignore_order=True) assert not diff, diff
无效尝试
常见但无效的做法:
-
65% 失败
Output is captured and interleaved unpredictably; hard to diff visually in CI.
-
50% 失败
Works but noisy and slow; you lose pytest's structured diff.