mirror of
https://github.com/pretix/pretix.git
synced 2026-08-25 13:12:00 +00:00
Tests: Run fakeredis on different virtual ports per pytest worker (#4555)
This commit is contained in:
@@ -39,5 +39,9 @@ def mocker_context():
|
|||||||
|
|
||||||
|
|
||||||
def get_redis_connection(alias="default", write=True):
|
def get_redis_connection(alias="default", write=True):
|
||||||
xdist_id = os.environ.get("PYTEST_XDIST_WORKER") or "None"
|
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
|
||||||
return fakeredis.FakeStrictRedis(server=fakeredis.FakeServer.get_server(f"127.0.0.1:None:v(7,0):{xdist_id}", (7, 0), server_type="redis"))
|
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"))
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
# <https://www.gnu.org/licenses/>.
|
# <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
import inspect
|
import inspect
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
@@ -82,27 +83,32 @@ def reset_locale():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def fakeredis_client(monkeypatch):
|
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(
|
with override_settings(
|
||||||
HAS_REDIS=True,
|
HAS_REDIS=True,
|
||||||
REAL_CACHE_USED=True,
|
REAL_CACHE_USED=True,
|
||||||
CACHES={
|
CACHES={
|
||||||
'redis': {
|
'redis': {
|
||||||
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
||||||
'LOCATION': 'redis://127.0.0.1',
|
'LOCATION': f'redis://127.0.0.1:{redis_port}',
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'connection_class': FakeConnection
|
'connection_class': FakeConnection
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'redis_session': {
|
'redis_session': {
|
||||||
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
||||||
'LOCATION': 'redis://127.0.0.1',
|
'LOCATION': f'redis://127.0.0.1:{redis_port}',
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'connection_class': FakeConnection
|
'connection_class': FakeConnection
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
|
||||||
'LOCATION': 'redis://127.0.0.1',
|
'LOCATION': f'redis://127.0.0.1:{redis_port}',
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'connection_class': FakeConnection
|
'connection_class': FakeConnection
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user