Skip to content

Commit

Permalink
[4.1.x] Fixed #34180 -- Added note about resetting language in test t…
Browse files Browse the repository at this point in the history
…ear-downs.

Co-authored-by: Faris Naimi <farisfaris66@gmail.com>

Backport of 40217d1 from main
  • Loading branch information
Durval Carvalho authored and felixxm committed Jan 31, 2023
1 parent 26b7a25 commit f586c12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ answer newbie questions, and generally made Django that much better:
Florian Apolloner <florian@apolloner.eu>
Florian Demmer <fdemmer@gmail.com>
Florian Moussous <florian.moussous@gmail.com>
fnaimi66 <https://github.com/fnaimi66>
Fran Hrženjak <fran.hrzenjak@gmail.com>
Francisco Albarran Cristobal <pahko.xd@gmail.com>
Francisco Couzo <franciscouzo@gmail.com>
Expand Down
8 changes: 8 additions & 0 deletions docs/topics/testing/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f586c12

Please sign in to comment.