Experimental fixture

This commit is contained in:
Raphael Michel
2024-10-24 23:36:09 +02:00
parent e37aba4f80
commit ff22b893f1

View File

@@ -20,8 +20,10 @@
# <https://www.gnu.org/licenses/>.
#
import inspect
import os
import pytest
from django.db import connection
from django.test import override_settings
from django.utils import translation
from django_scopes import scopes_disabled
@@ -113,3 +115,23 @@ def fakeredis_client(monkeypatch):
redis.flushall()
monkeypatch.setattr('django_redis.get_redis_connection', get_redis_connection, raising=False)
yield redis
if os.environ.get("GITHUB_WORKFLOW", ""):
@pytest.fixture(autouse=True)
def ensure_healthy_connection(request):
# We have no idea why this is neccessary. It shouldn't be, and it costs some performance.
# However, in ~August 2024 our tests became really flake on GitHub Actions (failing more than 80% of the time)
# for no apparent reason with some error messages related to PostgreSQL connection issues. This appears to
# work around it...
# Check if the test even has DB access
marker = request.node.get_closest_marker("django_db")
# Run actual test
yield
# If yes, do a dummy query at the end of the test
if marker:
with connection.cursor() as cursor:
cursor.execute("SELECT 1")