Skip to content
Latchkey

Django "ImproperlyConfigured: settings are not configured" in CI

Django reads configuration lazily from the module named by DJANGO_SETTINGS_MODULE. When that variable is unset (or settings.configure() was never called), the first access to any setting raises ImproperlyConfigured.

What this error means

A test or management step fails with "ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured." It typically appears when running pytest without the settings wired up.

pytest
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS,
but settings are not configured. You must either define the environment
variable DJANGO_SETTINGS_MODULE or call settings.configure() before
accessing settings.

Common causes

DJANGO_SETTINGS_MODULE not set in CI

pytest runs without the env var the app expects, so Django has no settings module to import.

pytest-django not configured

Without DJANGO_SETTINGS_MODULE in pytest config, pytest-django cannot bootstrap Django before tests.

How to fix it

Point pytest-django at the settings module

  1. Install pytest-django.
  2. Set DJANGO_SETTINGS_MODULE in pytest config (or the env).
  3. Re-run.
pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE = myproject.settings.test

Export the variable in the workflow

Set the env var for management-command style steps that run outside pytest.

.github/workflows/ci.yml
- run: python manage.py migrate
  env:
    DJANGO_SETTINGS_MODULE: myproject.settings.test

How to prevent it

  • Always set DJANGO_SETTINGS_MODULE for the test settings in CI.
  • Use pytest-django and declare the settings in pytest config.
  • Keep a dedicated test settings module checked into the repo.

Frequently asked questions

What causes ""settings are not configured""?
pytest runs without the env var the app expects, so Django has no settings module to import.
How do I fix "settings are not configured"?
Point pytest-django at the settings module

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card