pytest-dev / pytest-dev/pytest-django
pytest-django not picking up pytest sys.path auto-config for DJANGO_SETTINGS_MODULE
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
pytest automatically adds the first directory without a __init__.py to the sys.path when discovering tests.
Eg with the following structure:
.
├── AUTHORS
├── CHANGELOG.rst
├── COPYING
├── some_django_app
│ ├── __init__.py
│ ├── management
│ │ ├── commands
│ │ │ └── __init__.py
│ │ └── __init__.py
│ ├── middleware.py
│ └── templatetags
│ └── __init__.py
├── README.rst
├── setup.cfg
├── setup.py
├── tests
│ ├── conftest.py
│ ├── testproject
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ └── urls.py
│ └── test_xyz.py
└── tox.ini
When running tests, "tests/" is added to the sys.path, and in places like conftest.py you can add:
from django.conf import settings
from testproject import settings as testproject_settings
def pytest_configure():
settings.configure(**vars(testproject_settings))
However it appears as though simply adding DJANGO_SETTINGS_MODULE="testproject.settings" does not work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect tests/conftest.py and tests/testproject/settings.py, then run tests/test_xyz.py while comparing the working settings.configure path with DJANGO_SETTINGS_MODULE during test discovery. Done means DJANGO_SETTINGS_MODULE loads testproject.settings with the shown layout and the behavior is covered by the relevant test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100