# 导入错误：没有名为 tests 的模块

- **ID:** `python/importerror-no-module-named-tests`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试模块或包不在 Python 路径中，通常由于目录结构不正确或缺少 __init__.py。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## 解决方案

1. **Ensure __init__.py exists in test directory** (90% 成功率)
   ```
   touch tests/__init__.py
   ```
2. **Run pytest with PYTHONPATH set** (85% 成功率)
   ```
   PYTHONPATH=. pytest
   ```

## 无效尝试

- **Adding sys.path.append manually** — Works temporarily but not portable; can cause path conflicts. (50% 失败率)
- **Installing tests as a package via pip** — Tests are not meant to be installed; they are run from source. (70% 失败率)
