pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

How to change environment variable before django settings will be initialized?

Open mihalt opened this issue 1 year ago • 2 comments
trafficstars

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 avatar Aug 30 '24 18:08 mihalt

@mihalt does https://docs.pytest.org/en/stable/reference/reference.html#pytest.MonkeyPatch.setenv help?

covracer avatar Jan 07 '25 13:01 covracer

@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

mihalt avatar Jan 07 '25 13:01 mihalt