pytest-django "no Django settings specified" in CI
pytest-django needs to know which settings module to load and found none. Neither DJANGO_SETTINGS_MODULE in the environment nor a django_settings_module / DJANGO_SETTINGS_MODULE entry in pytest config was set, so it refuses to start.
What this error means
The test session aborts before collection with "Error: pytest-django: no Django settings specified. Set DJANGO_SETTINGS_MODULE or the django_settings_module pytest option."
pytest-django: no Django settings specified. Set DJANGO_SETTINGS_MODULE or the
django_settings_module pytest option.Common causes
DJANGO_SETTINGS_MODULE not set for the pytest step
The job runs pytest without exporting the settings module, and no pytest config supplies it.
No DJANGO_SETTINGS_MODULE in pytest config
The project relies on the environment variable, which is present locally but absent in CI.
How to fix it
Declare the settings in pytest config
Pin the settings module in pytest.ini so it is set regardless of the environment.
[pytest]
DJANGO_SETTINGS_MODULE = myproject.settings.ciExport the variable for the step
Set it at the job level so both pytest and manage.py commands agree.
env:
DJANGO_SETTINGS_MODULE: myproject.settings.ciHow to prevent it
- Pin DJANGO_SETTINGS_MODULE in pytest.ini so CI does not depend on the shell.
- Keep the same settings module in the workflow env for manage.py.
- Document required env vars in the CI settings module.