how to override settings per test file in django?

Viewed 296

I have two tests that when run at the same time fails:

pytest -s -v blog/tests/

but when run individually it passes:

pytest -s -v blog/tests/test_A.py
pytest -s -v blog/tests/test_B.py

I think the cause of this is both uses this pytest.fixture to override the settings:

test_A.py:

@pytest.fixture(autouse=True)
def override_url(settings):
    settings.A_URL = f'https://{ip_host}:{port}'

test_B.py

@pytest.fixture(autouse=True)
def override_url(settings):
    settings.B_URL = f'https://{ip_host}:{port}'

Is there a way to fix this fixture to avoid the tests failing when ran at the same time?

1 Answers

Try removing autouse=True

With the value set to ‘True’, all tests in this session just use the fixture automatically.

Related