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

其他格式: JSON · Markdown 中文 · English
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').

generic

解决方案

  1. 95% 成功率
    pytest -vv tests/test_x.py::test_dict
  2. 90% 成功率
    # pytest.ini
    [pytest]
    addopts = -vv --showlocals

无效尝试

常见但无效的做法:

  1. 70% 失败

    Adds noise; the real fix is enabling verbose diff.

  2. 75% 失败

    unittest diff is also truncated by default.

  3. 80% 失败

    Only shows the message, not the structured diff.