Tests: Run fakeredis on different virtual ports per pytest worker (#4555)

This commit is contained in:
Raphael Michel
2024-10-25 16:44:22 +02:00
committed by GitHub
parent b46c0eba0c
commit 565f5e2ea7
2 changed files with 15 additions and 5 deletions

View File

@@ -20,6 +20,7 @@
# <https://www.gnu.org/licenses/>.
#
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
}