python
config_error
ai_generated
true
Failed example: print({'a': 1, 'b': 2}) Expected: {'a': 1, 'b': 2} Got: {'a': 1, 'b': 2} 1 items had failures
ID: python/pytest-doctest-optionflags-mismatch
80%Fix Rate
84%Confidence
0Evidence
2024-04-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Dict ordering differs across Python versions or the output has trailing whitespace/ordering that differs. Without NORMALIZE_WHITESPACE or ELLIPSIS, doctest requires byte-exact output.
generic中文
字典顺序在不同 Python 版本间不同,或输出存在尾随空白/顺序差异。未启用 NORMALIZE_WHITESPACE 或 ELLIPSIS 时,doctest 要求输出逐字节一致。
Workarounds
-
90% success
Enable normalization in pytest.ini: [tool.pytest.ini_options] doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS Or in docstring: >>> print(d) # doctest: +NORMALIZE_WHITESPACE
-
92% success
Sort dict output explicitly in the docstring example: >>> sorted(d.items()) [('a', 1), ('b', 2)]
Dead Ends
Common approaches that don't work:
-
75% fail
Breaks on other Python versions where dict ordering or repr differ.
-
50% fail
Loses documentation test coverage; hides real regressions.