#34180: Document that setting language in tests affects other tests
-------------------------------------+-------------------------------------
Reporter: Václav Řehák | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 4.1
Severity: Normal | Resolution:
Keywords: documentation i18n | Triage Stage: Accepted
tests |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Raphaël Barrois):
I'll add the results of the extra investigation I did in #34181 (sorry for
not seeing this ticket, it wasn't here when I started writing mine 😅):
- The issue happened with the fix for #5241 in
https://github.com/django/django/commit/aa089b106b6cfc9a47cd54a0f9eb44bd44811ed9
- Django's `LocaleMiddleware` no longer calls `translation.deactivate()`
as part of its request cleanup.
However, the pattern shown here is very close to typical code used in
tests, where strings marked for translation are tested against the value
in the default locale.
I feel that a documentation fix stating "Every test asserting on a string
marked for translation should wrap said assertion with
`translation.override`" wouldn't actually help users, as that would add a
significant amount of boilerplate to test cases.
If the recommended solution is to call `translation.deactivate()` in each
test case' `tearDown`, I'd suggest including that in Django's source code.
Another option could be for the test client to deactivate translations
post-request when it detects that the `LocaleMiddleware` is enabled.
Otherwise, we could also explore the possibility to restore the locale
context in some post-request handler, server-side.
--
Ticket URL: <https://code.djangoproject.com/ticket/34180#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070184a9ff3fd5-48ca4380-8ae4-4414-9a8d-8f639b68efcb-000000%40eu-central-1.amazonses.com.