django.test: @override_settings(LANGUAGE_CODE = 'xx') does not affect the default language in a test

209 views
Skip to first unread message

Yunshi Tan

unread,
Oct 6, 2015, 10:27:50 AM10/6/15
to Django users
Let's say we have a default language code in settings.py
 
   LANGUAGE_CODE = 'en'

Then we have

  >> from django.utils import translation
  >> assert translation.get_language() == 'en'

We are good by now.

Then in a test, I would like to override the default language. Let's say I have

@override_settings(LANGUAGE_CODE='fr')
class SomeTestCase(TestCase):

    def test_some_case(self):
self.assert(
translation.get_language(), 'en') # it will pass
  self.assert(translation.get_language(), 'fr') # it would fail


Is this a bug?

Tom Evans

unread,
Oct 6, 2015, 11:47:24 AM10/6/15
to django...@googlegroups.com
I don't think so, if simply because 'translation.get_language()' gets
the currently activated language, not what the current value of
"settings.LANGUAGE_CODE" is.

LANGUAGE_CODE shouldn't normally change, so I don't think any code
detecting when it is changed is warranted. It seems that what you want
to do is to change the currently activated language and perform some
tests - translation.activate_language() serves this purpose better
than patching settings.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages