[Answer]-How to add apps to INSTALLED_APPS for tests?

1👍

You could run the tests with a special settings.py, by setting the DJANGO_SETTINGS_MODULE environment variable. This special “testsettings.py” can import * from the normal settings.py, and then add the necessary extra apps to INSTALLED_APPS.

Remember that settings.py files are just ordinary Python modules, so you can add any logic you want to get the list of extra apps from somewhere.

0👍

Django provides the modify_settings() context manager for easier settings changes:

class TestSomeApp(TestCase):

    def test_some_app(self):
        with self.modify_settings(
            INSTALLED_APPS={"prepend": "some_app"}
        ):
            # ...

https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.SimpleTestCase.modify_settings

Leave a comment