From c4db8fcba742e8a792ff6ac26a6d79f803fc3f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Tue, 19 Nov 2024 15:28:15 +0100 Subject: [PATCH] more efficient fix for cache issue --- lemarche/www/siaes/tests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lemarche/www/siaes/tests.py b/lemarche/www/siaes/tests.py index c15aa1a83..40f2cad28 100644 --- a/lemarche/www/siaes/tests.py +++ b/lemarche/www/siaes/tests.py @@ -1,6 +1,7 @@ from unittest import mock from django.contrib.gis.geos import Point +from django.contrib.sites.models import Site from django.test import TestCase from django.urls import reverse @@ -59,8 +60,9 @@ def setUpTestData(cls): def test_search_num_queries(self): url = reverse("siae:search_results") - # fix cache issue in parallel testing context, "SELECT 'django_site'" query appears additionally otherwise - self.client.get(url) + # fix cache issue in parallel testing context because only first call fetches database + # See https://docs.djangoproject.com/en/5.1/ref/contrib/sites/#caching-the-current-site-object + Site.objects.get_current() with self.assertNumQueries(12): response = self.client.get(url)