# 导入文件不匹配：
  /app/tests/test_models.py 的 __file__ 属性为：
    /app/tests/test_models.py
  与要收集的测试文件不同：
    /app/tests/unit/test_models.py
提示：删除 __pycache__ / .pyc 文件，和/或为测试文件模块使用唯一的基名

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

## 根因

两个测试文件在不同目录下共享相同基名（test_models.py），但两个目录都不是 Python 包（缺少 __init__.py），因此 pytest 将两者都作为顶层模块 `test_models` 导入，导致冲突。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   touch tests/__init__.py tests/unit/__init__.py
# pytest then imports as tests.test_models and tests.unit.test_models
   ```
2. **** (90% 成功率)
   ```
   mv tests/test_models.py tests/test_api_models.py
mv tests/unit/test_models.py tests/unit/test_db_models.py
   ```
3. **** (85% 成功率)
   ```
   # pytest.ini
[pytest]
addopts = --import-mode=importlib
   ```

## 无效尝试

- **** — Clearing caches removes stale bytecode but does not fix the underlying module-name collision; the error reappears on the next run. (85% 失败率)
- **** — Changing PYTHONPATH does not give the two files distinct module names; the collision is due to identical basenames without package context. (90% 失败率)
