# E   pytest.PytestAssertRewriteWarning: 模块已被导入，无法重写

- **ID:** `python/pytest-assertion-introspection-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

插件或 conftest 在 pytest 断言重写器注册之前导入了模块，导致该模块中的 assert 语句未被重写，产生较差的失败信息。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Register the module for rewriting before any import:

# conftest.py (top)
import pytest
pytest.register_assert_rewrite('myapp.core')

import myapp.core  # after registration
   ```
2. **** (85% 成功率)
   ```
   Avoid importing application modules at conftest top level; import inside fixtures instead.
   ```

## 无效尝试

- **** — The warning is suppressed but assertion rewriting remains disabled for that module. (85% 失败率)
- **** — Import order still places it after pytest's plugin loading in many cases, so the warning persists. (80% 失败率)
