I want to test a small reusable app which comes with its own settings module. Global (project) settings are accessed inside app’s settings to support variables’ overriding, e.g.
# in <my_app>/settings.py
from django.conf import settings
MY_SETTING_VAR = getattr(settings, 'MY_OVERRIDDEN_VAR', False)
When I run tests with manage.py test myapp I get the following:
ImportError: Settings cannot be imported, because environment
variable DJANGO_SETTINGS_MODULE is undefined.
What is the right way to run tests in this case?
I’m not sure, i tested exactly what you posted and it works for me:
You want to make sure your actual code matches this working code.
It’s better for an app to include a dummy project that demonstrates the app or at least allows testing. For example: