问题
I need to test my Django app with py.test. Hence, I need to tell py.test which is Django's settings module. The command I use for py.test is: ~/GitHub/django-training$ py.test --ds=training.settings
Unfortunately, I get this error: ERROR: Could not import settings 'training.settings' (Is it on sys.path?): No module named training.settings
Is looks very odd, because my folder structure looks like this:
django-training
training
settings.py
and my sys.path
contains the /home/user/GitHub/django-training
entry on the first position.
Now, why can't I use that settings file?
回答1:
The training directory is probably really not on sys.path. A usual approach is to run in a virtualenv and run pip install -e .
in the django-training
directory, assuming it has a setup.py
. But any other means which fits with your development workflow is fine.
来源:https://stackoverflow.com/questions/19638858/cannot-import-settings-in-django