24👍
Because django.conf.settings is lazy it will attempt to import settings module only when you try to access it. That’s why your test doesn’t fail when you simply import settings object.
Your problem is already discussed here: https://github.com/pelme/pytest_django/issues/23
This is an issue with pytest and not with pytest-django itself. Pytest for some reason removes current directory from sys.path. It should be easy to work around it.
Solution 1:
PYTHONPATH=`pwd` py.test
Solution 2:
add this to your conftest.py (I assumed that conftest.py is in the same directory your apps are):
import os
import sys
sys.path.append(os.path.dirname(__file__))
Solution 3 (if you’re using virtualenv wrapper):
When you start a new project just add project’s root directory to virtualenv’s PYTHONPATH by
executing this line in your project’s directory:
add2virtualenv .
1👍
From the docs, it seems that base
is already in your path – so maybe you want to be using
py.test --ds=settings.settings
- [Django]-How to serve media files on Django production environment?
- [Django]-How can I handle Exceptions raised by dango-social-auth?
- [Django]-Django: how to do calculation inside the template html page?
- [Django]-How to test auto_now_add in django
- [Django]-Row level permissions in django
- [Django]-Problems extend change_form.html in django admin
0👍
You run the second program without the --ds=base.settings.settings
argument and not the first. This is where the error appears to be coming from.
Also when importing code of the same name settings
I would be tempted to do something like:
from base.settings import settings as foo
from django.conf import settings as bar
- [Django]-Django 1.7 – App 'your_app_name' does not have migrations
- [Django]-Http POST drops port in URL
- [Django]-Django return file over HttpResponse – file is not served correctly
- [Django]-Django dynamic forms – on-the-fly field population?
- [Django]-Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests?
- [Django]-Django project models.py versus app models.py