python
config_error
ai_generated
true
pytest.PytestConfigWarning: Unknown config option: DJANGO_SETTINGS_MODULE E django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured.
ID: python/pytest-django-settings-not-configured
80%Fix Rate
86%Confidence
0Evidence
2024-08-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 4.x | active | — | — | — |
Root Cause
pytest-django is not installed or not active, so DJANGO_SETTINGS_MODULE in pytest.ini is ignored and Django isn't configured before import.
generic中文
pytest-django 未安装或未启用,导致 pytest.ini 中的 DJANGO_SETTINGS_MODULE 被忽略,Django 在导入前未配置。
Workarounds
-
95% success
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"
Dead Ends
Common approaches that don't work:
-
60% fail
Works only if `django.setup()` is also called; still fails on fixtures.
-
55% fail
pytest-django does this itself; double-init causes warnings and test DB issues.