# ImportError: 导入文件不匹配:
  'test_models.py' 从 /app/tests/unit/test_models.py 导入
  'test_models.py' 从 /app/tests/integration/test_models.py 导入
提示: 确保测试模块/包具有有效的 Python 名称。

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

## 根因

两个测试文件同名但位于不同目录且没有 __init__.py 文件，pytest 基于 rootdir 的模块导入发生冲突，导致第二次导入失败。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Add __init__.py to each test directory so pytest treats them as packages:

touch tests/unit/__init__.py tests/integration/__init__.py
   ```
2. **** (90% 成功率)
   ```
   Or set import mode globally in pytest.ini:

[pytest]
addopts = --import-mode=importlib
   ```

## 无效尝试

- **** — Removes real test coverage; the collision returns as soon as another same-named file is added. (70% 失败率)
- **** — Fixes the single run but CI still uses the default mode and fails identically. (75% 失败率)
