pytest-dev / pytest-dev/pytest-xdist

Django Problem with -n 1

Open
#359 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
1.9k
Forks
287
Avg merge
9h 30m
Merged PRs (30d)
2

Description

When I run pytest with xdist, I get an error that I don't get if I run the same exact command but without the -n 1 flag. Any number of processors specified is sufficient to generate the error.

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

Do I need to do something special to avoid this? When I had this problem previously, it seemed to fix the issue when I put:

[pytest]
addopts = -p no:django

in my pytest.ini. But the problem has come back now. I tried upgrading pytest-django, but it is the same error essentially:

django.core.exceptions.ImproperlyConfigured: Requested settings, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
pytest (3.9.1)
pytest-cov (2.6.0)
pytest-django (3.4.3)
pytest-forked (0.2)
pytest-mock (1.6.3)
pytest-sugar (0.9.1)
pytest-watch (4.2.0)
pytest-xdist (1.23.2)

I understand that I can set DJANGO_SETTINGS_MODULE, but why do I need to? The tests I'm running do not import django at all and if I don't use xdist, then this isn't an issue.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported pytest run with xdist and -n 1, comparing it with the same run without xdist. Inspect how pytest-django and pytest-xdist interact with pytest.ini, DJANGO_SETTINGS_MODULE, and the disabled django plugin. Done means the cause is identified and the failing configuration no longer raises Django's settings error.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.