I'm trying to automate the test rerun after a change while developing. After searching around a little sniffer seemed fine. But if I run it my tests fail with this error:
ERROR: Failure: ImportError (Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.)
if I run them manually they pass. Do you have a clue why sniffer won't work?
You can get
sniffer
to read your settings by creating ascent.py
file in the same directory asmanage.py
.Here's what mine looks like:
Which will get you as far as
sniffer
reading your settings, but then you'll run into other problems — basically,sniffer
just runs your tests usingnose
, which isn't the same thing that themanage.py test
does whendjango-nose
is installed.Anybody know what else needs to be in
scent.py
forsnigger
to with with Django?Something like the following as your
scent.py
should work:Which you can then call as
sniffer -x appName
.Trying to guess where the problem may reside: it seems you need to explicitly set the position of your settings.py file.
if you're running your test from a subprocess' call you can use the following command:
otherwise you can set environment variables with the following command:
(change your_project with the name of your django project)
if you're running a command like "./manage.py tests" you can add the former lines at the beginning of manage.py (there are other ways but I need to see the code to provide a more precise solution)