From f586c12f0167f51c9e398d7214ac1aa5522f1460 Mon Sep 17 00:00:00 2001 From: Durval Carvalho Date: Wed, 21 Dec 2022 14:25:24 -0500 Subject: [PATCH] [4.1.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 f77693fea5..fb9550f079 100644 --- a/AUTHORS +++ b/AUTHORS @@ -326,6 +326,7 @@ answer newbie questions, and generally made Django that much better: Florian Apolloner Florian Demmer Florian Moussous + fnaimi66 Fran Hrženjak Francisco Albarran Cristobal Francisco Couzo diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index f9764998ca..a7ac9023f3 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -638,6 +638,14 @@ or by including the ``Accept-Language`` HTTP header in the request:: response = self.client.get('/', HTTP_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