python
data_error
ai_generated
true
ValueError: mypkg.mod 的文档字符串第 1 行示例后缺少空行
ValueError: line 1 of the docstring for mypkg.mod lacks blank line after the examples
ID: python/pytest-doctest-module-not-found
80%修复率
84%置信度
0证据数
2025-02-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest --doctest-modules 将文档字符串解析为 doctest;'>>>' 块后缺少空行或缩进错误会在收集阶段触发此 ValueError。
English
pytest --doctest-modules parses docstrings as doctests; missing blank line after '>>>' block or malformed indentation triggers this ValueError during collection.
解决方案
-
94% 成功率
def add(a, b): """Return a + b. >>> add(1, 2) 3 """ return a + b -
88% 成功率
# pyproject.toml [tool.pytest.ini_options] addopts = "--doctest-modules" doctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"]
无效尝试
常见但无效的做法:
-
70% 失败
Skips legitimate doctests and hides the formatting bug; other modules with the same issue still fail.
-
75% 失败
Loses documentation and breaks help() output; doesn't address the formatting pattern for future modules.