diff --git a/src/pretix/testutils/mock.py b/src/pretix/testutils/mock.py index c4a920d6b8..30b9046ab2 100644 --- a/src/pretix/testutils/mock.py +++ b/src/pretix/testutils/mock.py @@ -39,5 +39,9 @@ def mocker_context(): def get_redis_connection(alias="default", write=True): - xdist_id = os.environ.get("PYTEST_XDIST_WORKER") or "None" - return fakeredis.FakeStrictRedis(server=fakeredis.FakeServer.get_server(f"127.0.0.1:None:v(7,0):{xdist_id}", (7, 0), server_type="redis")) + worker_id = os.environ.get("PYTEST_XDIST_WORKER") + if worker_id.startswith("gw"): + redis_port = 1000 + int(worker_id.replace("gw", "")) + else: + redis_port = 1000 + return fakeredis.FakeStrictRedis(server=fakeredis.FakeServer.get_server(f"127.0.0.1:{redis_port}:redis:v(7, 0)", (7, 0), server_type="redis")) diff --git a/src/tests/conftest.py b/src/tests/conftest.py index b78b025449..9480872cab 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -20,6 +20,7 @@ # . # import inspect +import os import pytest from django.test import override_settings @@ -82,27 +83,32 @@ def reset_locale(): @pytest.fixture def fakeredis_client(monkeypatch): + worker_id = os.environ.get("PYTEST_XDIST_WORKER") + if worker_id.startswith("gw"): + redis_port = 1000 + int(worker_id.replace("gw", "")) + else: + redis_port = 1000 with override_settings( HAS_REDIS=True, REAL_CACHE_USED=True, CACHES={ 'redis': { 'BACKEND': 'django.core.cache.backends.redis.RedisCache', - 'LOCATION': 'redis://127.0.0.1', + 'LOCATION': f'redis://127.0.0.1:{redis_port}', 'OPTIONS': { 'connection_class': FakeConnection } }, 'redis_session': { 'BACKEND': 'django.core.cache.backends.redis.RedisCache', - 'LOCATION': 'redis://127.0.0.1', + 'LOCATION': f'redis://127.0.0.1:{redis_port}', 'OPTIONS': { 'connection_class': FakeConnection } }, 'default': { 'BACKEND': 'django.core.cache.backends.redis.RedisCache', - 'LOCATION': 'redis://127.0.0.1', + 'LOCATION': f'redis://127.0.0.1:{redis_port}', 'OPTIONS': { 'connection_class': FakeConnection }