1

I have different settings for different environments for my application, such as local, dev, stage, production. So, when I run my apps, say, locally, I pass the settings as the parameter to manage.py, e.g. python3 manage.py runserver 0.0.0.0:8080 --settings=myapp.settings.local, and indeed all my settings are correctly initialised, e.g. DEBUG is True as it is set in my settings file, and not False as it is in defaultsettings.py.

However, when I try to run tests with python3 manage.py test --settings=myapp.settings.local, the value of DEBUG is set to false, that is it is loaded from defaultsettings.py. Why does that happen and how can I fix this?

Ibolit
  • 9,218
  • 7
  • 52
  • 96

2 Answers2

1

Turns out that when you run your tests, all your settings are just like they are in your settings file except for DEBUG. DEBUG is always set to False to make the set up as close to production as possible.

I ended up following this post: Detect django testing mode

import sys TESTING = sys.argv[1:2] == ['test']

Ibolit
  • 9,218
  • 7
  • 52
  • 96
0

Make sure that in the test you import the settings like this: from django.conf import settings

Cristian Mora
  • 41
  • 1
  • 3