# 收集 doctests 时出错
File "...", line 1, in <module>
ModuleNotFoundError: 没有名为 'myapp' 的模块

- **ID:** `python/pytest-doctest-missing-module`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest --doctest-modules 发现项目树下的 .py 文件（包括 examples/ 或 docs/），这些文件导入包但包未安装或不在 sys.path 上。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   pip install -e .
pytest --doctest-modules src/myapp -q
   ```
2. **** (90% 成功率)
   ```
   # pyproject.toml
[tool.pytest.ini_options]
testpaths = ['src/myapp', 'tests']
pythonpath = ['src']
addopts = '--doctest-modules'
   ```

## 无效尝试

- **** — Skips real doctests in examples; other directories still fail if the package is not importable. (60% 失败率)
- **** — Boilerplate in every file; breaks when run from a different cwd. (70% 失败率)
