python
data_error
ai_generated
true
ValueError: line 1 of the docstring for mypkg.mod lacks blank line after the examples
ID: python/pytest-doctest-module-not-found
80%Fix Rate
84%Confidence
0Evidence
2025-02-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest --doctest-modules parses docstrings as doctests; missing blank line after '>>>' block or malformed indentation triggers this ValueError during collection.
generic中文
pytest --doctest-modules 将文档字符串解析为 doctest;'>>>' 块后缺少空行或缩进错误会在收集阶段触发此 ValueError。
Workarounds
-
94% success
def add(a, b): """Return a + b. >>> add(1, 2) 3 """ return a + b -
88% success
# pyproject.toml [tool.pytest.ini_options] addopts = "--doctest-modules" doctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"]
Dead Ends
Common approaches that don't work:
-
70% fail
Skips legitimate doctests and hides the formatting bug; other modules with the same issue still fail.
-
75% fail
Loses documentation and breaks help() output; doesn't address the formatting pattern for future modules.