pytest-dev / pytest-dev/pytest-django
How to change environment variable before django settings will be initialized?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
I try to use this, but in fact settings var that was initialized in docker container doesn't change.
conftest.py
@pytest.hookimpl(tryfirst=True)
def pytest_load_initial_conftests(early_config, parser, args):
os.environ["CH_BASE_OF_URL"] = 'https://api.cowho.com'
settings.py
CH_BASE_URL = os.environ.get('CH_BASE_OF_URL')
I tried to use pytest_configure. It doesn't work too. Just passing of settings fixture to the test doesn't work for me, because initialization of data appears after django_db_blocker.unblock() by signal and depends from settings variable too.
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
Start with the conftest.py pytest_load_initial_conftests hook and the settings.py environment lookup shown in the report. Reproduce the initialization order with pytest and django_db_blocker.unblock(), including the signal that creates data. Done means documenting or verifying a supported way to set the environment variable before Django settings and signal initialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100