# 导入错误：无法从 'test_app' 导入名称 'app'（未知位置）

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

## 根因

使用 importlib 导入模式时，测试模块作为顶级模块导入，导致名称冲突或缺失导入。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   from mypackage import app
   ```
2. **** (85% 成功率)
   ```
   [pytest]
import-mode = importlib
   ```

## 无效尝试

- **** — This may not be desirable if you need importlib for other reasons. (60% 失败率)
- **** — This can cause other import issues. (70% 失败率)
