From af396ce3f9a15db27173469b1eb2388810dd00c3 Mon Sep 17 00:00:00 2001 From: Durval Carvalho Date: Wed, 21 Dec 2022 14:25:24 -0500 Subject: [PATCH] [4.2.x] Fixed #34180 -- Added note about resetting language in test tear-downs. Co-authored-by: Faris Naimi Backport of 40217d1a82b0c16cddba377325d12b2c253f402a from main --- AUTHORS | 1 + docs/topics/testing/tools.txt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/AUTHORS b/AUTHORS index db1454c5ee..4e91d7b3f3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -330,6 +330,7 @@ answer newbie questions, and generally made Django that much better: Florian Apolloner Florian Demmer Florian Moussous + fnaimi66 Fran Hrženjak Francesco Panico Francisco Albarran Cristobal diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 1ecc97a2a9..ba42180744 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -685,6 +685,14 @@ or by including the ``Accept-Language`` HTTP header in the request:: response = self.client.get("/", headers={"accept-language": "fr"}) self.assertEqual(response.content, b"Bienvenue sur mon site.") +.. note:: + + When using these methods, ensure to reset the active language at the end of + each test:: + + def tearDown(self): + translation.activate(settings.LANGUAGE_CODE) + More details are in :ref:`how-django-discovers-language-preference`. If the middleware isn't enabled, the active language may be set using