Test with double override_settings (class + method) takes few minutes to complete

Hello,

Can anyone confirm this situation or provide a solution to this problem?

Problem:

Long time test execution when using override_settings on class and test. The setting overrode on test is LANGUAGE_CODE.

Description:

I have a TestCase with override_settings decorator (overriding anything - custom settings or django internal settings). The TestCase has a test, which also uses override_settings to change the language. When I run the test, it takes few (5-7) minutes to execute, but finally finishes good.
It’s really annoying when I have about 25 minutes of tests which take about 40 minutes (because of 3 tests with this situation).

Example:

@override_settings(ANY_SETTING='overrided')
class MyTestCase(TestCase):
    @override_settings(LANGUAGE_CODE='en')
    def test_translation(self):
        # perform test

Executing this test takes few minutes. Always.

I tested overriding different settings and for any other setting - it runs fast. The only problem I encounter is the situation in example: overriding any setting on class and LANGUAGE_CODE on test.

What I tried:

  • use ‘with override_settings()’
  • overriding different settings to check and ensure this specific example is

Just to be clear - if you remove the override of LANGUAGE_CODE, the test runs fast? (Perhaps after removing some assertions)

I’m not aware of any particular slowdown from overriding LANGUAGE_CODE. I can imagine it adds some overhead but it’s unlikely to be in the order of minutes.

The first thing I recommend in my book Speed Up Your Django Tests is to profile. You can do that with py-spy and its speedscope output and get good results pretty quickly. You should be able to track down the source of the slowdown like this. Hope that helps - let us know what you find.

1 Like