Tests: Add separation of database lock indices by pytest worker (#4553)

* Add separation of database lock indices by pytest worker

* Fix ID derivation

* Update conftest.py
This commit is contained in:
Raphael Michel
2024-10-25 22:05:02 +02:00
committed by GitHub
parent 9ca1573fcf
commit 8f1d53d016

View File

@@ -84,7 +84,7 @@ def reset_locale():
@pytest.fixture
def fakeredis_client(monkeypatch):
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
if worker_id.startswith("gw"):
if worker_id and worker_id.startswith("gw"):
redis_port = 1000 + int(worker_id.replace("gw", ""))
else:
redis_port = 1000
@@ -119,3 +119,13 @@ def fakeredis_client(monkeypatch):
redis.flushall()
monkeypatch.setattr('django_redis.get_redis_connection', get_redis_connection, raising=False)
yield redis
@pytest.fixture(autouse=True)
def set_lock_namespaces(request):
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
if worker_id and worker_id.startswith("gw"):
with override_settings(DATABASE_ADVISORY_LOCK_INDEX=int(worker_id.replace("gw", ""))):
yield
else:
yield