# 导入文件不匹配：
  /proj/tests/test_a.py 具有 __pycache__ ...
  导入的模块 'test_a' 具有此 __file__ 属性：
    /proj/tests/sub/test_a.py

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

## 根因

两个测试文件在不同目录下具有相同的基本名称，且没有 __init__.py，导致 Python 模块缓存在模块名 'test_a' 上发生冲突。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   touch tests/__init__.py tests/sub/__init__.py
# then rerun: pytest -q
   ```
2. **** (90% 成功率)
   ```
   # pytest.ini
[pytest]
addopts = --import-mode=importlib
   ```
3. **** (85% 成功率)
   ```
   mv tests/test_a.py tests/test_alpha.py
mv tests/sub/test_a.py tests/sub/test_a_sub.py
   ```

## 无效尝试

- **** — Cache regeneration recreates the same collision on the next run. (90% 失败率)
- **** — Hash randomization is unrelated to module name resolution. (95% 失败率)
- **** — May work short-term but the same pattern recurs as the suite grows. (40% 失败率)
