Opened 4 years ago

Closed 4 years ago

#15280 closed (wontfix)

Django validation error messages are always shown in English when running unit tests

Reported by: denilsonsa Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

How to reproduce:

  • Start a new project and set LANGUAGE_CODE to something other than 'en-us'. For instance, let's put 'pt-br'.
  • Create a view that renders a bounded form.
  • Pass invalid data to that form, so that the form will output some (django built-in) validation error messages.
  • Look at the error message at the browser. Notice it is in Portuguese (or whatever language you have set).
  • Now write a unit test that checks if your view actually shows that error message.
  • BOO! The test fails! When running unit tests, the django error messages are shown in English, ignoring the LANGUAGE_CODE setting.

I'm attaching a tarball with a minimalistic project showing this bug.

In my opinion, django should behave the same whenever running as server or running the unit tests. Thus, I believe this behavior is a bug.

Tested against Django 1.2.4

Attachments (1)

django_language_during_tests.tar.gz (3.5 KB) - added by denilsonsa 4 years ago.

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by denilsonsa

comment:1 Changed 4 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

What about re-usable apps that ship with tests that include testing error strings as you are talking about? They would all suddenly start failing on projects with non-en-us locales set, because they were written to test against default en-us string values.

If you want to test a specific language error string, then you need to activate that locale in your test. How to do that is noted on this page: http://docs.djangoproject.com/en/1.2/howto/custom-management-commands/.

Note: See TracTickets for help on using tickets.
Back to Top