django-constance
django-constance copied to clipboard
override_config in multithreaded (parallel) tests execution
Our test suite that utilizes override_config
decorator sometimes fails when we execute tests in parallel (value in config
in the test body is different than the one defined in override_config
).
My theory is that config in test_A gets overridden in the middle of the test execution by test_B that started after override_config
from test_A has been applied.
For parallel testing and overriding, have you considered using another backend that would prevent this from happening (try in-memory for example)? It would also help to know which one you are using in the tests.
Which one would work? If they are running on the same machine in parallel, they would still grab the value from the same spot
Recently I've run through a pretty similar issue. In my case using the database backend with different spots for each site it turned out it also used the in-memory cache which affected all the sites and messed up config values. For such case you can either turn the cache off
CONSTANCE_DATABASE_CACHE_BACKEND
or (like I do) set a different cache store prefix for each site
CONSTANCE_DATABASE_PREFIX
Currently trying this (using pytest):
@pytest.fixture(scope='session', autouse=True)
def setup_constance_prefix(worker_id):
"""For parallel test-running, use non-overlapping prefixes for Constance config vars to avoid clobbering."""
if worker_id:
settings.CONSTANCE_REDIS_PREFIX = 'constance:{}:'.format(worker_id)