pytest-django
pytest-django copied to clipboard
How to change environment variable before django settings will be initialized?
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.
@mihalt does https://docs.pytest.org/en/stable/reference/reference.html#pytest.MonkeyPatch.setenv help?
@mihalt does https://docs.pytest.org/en/stable/reference/reference.html#pytest.MonkeyPatch.setenv help?
Looks like that this helped in my case https://github.com/pytest-dev/pytest-django/issues/1058#issuecomment-2405683141