# pytest.PytestConfigWarning: 未知配置项: DJANGO_SETTINGS_MODULE
E   django.core.exceptions.ImproperlyConfigured: 请求设置 INSTALLED_APPS，但设置未配置。

- **ID:** `python/pytest-django-settings-not-configured`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest-django 未安装或未启用，导致 pytest.ini 中的 DJANGO_SETTINGS_MODULE 被忽略，Django 在导入前未配置。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   pip install pytest-django, then in pyproject.toml:
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "myproj.settings"
python_files = "tests.py test_*.py *_tests.py"
   ```

## 无效尝试

- **** — Works only if `django.setup()` is also called; still fails on fixtures. (60% 失败率)
- **** — pytest-django does this itself; double-init causes warnings and test DB issues. (55% 失败率)
