Cannot run unit tests because environment variable DJANGO_SETTINGS_MODULE is undefined
I've had this problem with both the 1.01 build and 1.1. I am using virtualenv. This is the stack trace I get:
File "/home/rob/safe_amerika/development/vibrant_company/sources/wondervault/lib/python2.6/site-packages/django/conf/__init__.py", line 38, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
Any clues anyone?
I am grateful in advance.
_____________
Robert Moskal
Most Media
Brooklyn, USA
Please sign in to leave a comment.
I will answer my own question. I am a django newbie.
First, if you want to run unit tests against your code you have to add the directory to INSTALLED_APPS list in settings. after you do this, and issue synchdb you can run your test as a target of manage. You can do this from the pycharm ui as well.
One more gotcha, your directory must have a models.py file in order for the tests to run. This seems annoying but I can live with it.
Regards,
Robert
I'm having the same problem (DJANGO_SETTINGS_MODULE is undifined), and can't figure out how to run tests on a specific app. I can run them for the entire Django project, but I only want to run them for one app.
Some help with "run your test as a target of manage" would be appreciated :-)