# Failed: [doctest] mymodule.func
意外异常: ModuleNotFoundError: 没有名为 'mymodule' 的模块

- **ID:** `python/pytest-doctest-import-error`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest-doctest 尝试从 doctest 文件导入模块，但模块不在 sys.path 上，因为测试从不同目录运行。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   pip install -e .
pytest --doctest-modules
   ```
2. **** (90% 成功率)
   ```
   In pytest.ini: `[pytest]
pythonpath = .`
   ```

## 无效尝试

- **** — May work locally but fails in CI where the working directory differs. (60% 失败率)
- **** — Loses doctest coverage; not a fix. (80% 失败率)
