From 55641f7e50db347177ac3ceb7f3c53cb3c639318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Thu, 7 Nov 2024 11:56:57 +0100 Subject: [PATCH] fix cache issue in parallel testing context --- lemarche/www/siaes/tests.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lemarche/www/siaes/tests.py b/lemarche/www/siaes/tests.py index 15793bae0..c15aa1a83 100644 --- a/lemarche/www/siaes/tests.py +++ b/lemarche/www/siaes/tests.py @@ -58,6 +58,10 @@ 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) + with self.assertNumQueries(12): response = self.client.get(url) siaes = list(response.context["siaes"]) @@ -1032,11 +1036,14 @@ def test_search_query_no_result(self): mock_siaes_similarity_search.assert_called_once() def test_search_query_with_results(self): - with mock.patch( - "lemarche.utils.apis.api_elasticsearch.siaes_similarity_search" - ) as mock_siaes_similarity_search, mock.patch( - "lemarche.utils.apis.api_elasticsearch.siaes_similarity_search_with_city" - ) as mock_siaes_similarity_search_with_city: + with ( + mock.patch( + "lemarche.utils.apis.api_elasticsearch.siaes_similarity_search" + ) as mock_siaes_similarity_search, + mock.patch( + "lemarche.utils.apis.api_elasticsearch.siaes_similarity_search_with_city" + ) as mock_siaes_similarity_search_with_city, + ): mock_siaes_similarity_search.return_value = [self.siae_two.pk, self.siae_three.pk, self.siae_four.pk] url = self.url + "?semantic_q=entretien espace vert&id_semantic_city_name=&semantic_city=" response = self.client.get(url)