Opened 18 years ago
Closed 18 years ago
#6255 closed (fixed)
setup_environ(company.django.settings) won't work
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Core (Other) | Version: | 0.96 |
| Severity: | Keywords: | setup_environ py.test | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi,
I had problem with using django.core.management.setup_environ() function in this env:
- c:\python - pythonpath
- C:\python\company\django - django project root
- C:\python\company\django\reports - is django application
- -> company.django.reports is python package
in C:\python\company\django\reports\tests\test_views.py i have:
from django.core.management import setup_environ
import company.django.settings as settings
setup_environ(settings)
> from django.test.client import Client
but it reports error (django 0.96):
django\conf\__init__.py:57
try:
mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
except ImportError, e:
> EnvironmentError: Could not import settings 'django.settings' (Is it on sys.path? Does it have syntax errors?): No module named settings
After some investigation I found out that from module name company.django.settings first part (company) was dropped out in:
in django\core\management\__init__.py->setup_environ function:
# Set DJANGO_SETTINGS_MODULE appropriately.
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
I made a patch to this (sorry for not sending you in .patch/.diff format):
# Set DJANGO_SETTINGS_MODULE appropriately.
os.environ['DJANGO_SETTINGS_MODULE'] = '%s' % (settings_mod.__name__)
After this there is no problem. Hope it'll help (someone).
Btw. I prefer py.test (http://codespeak.net/py/dist/test.html) testing framework, so in this way I have setup py.test to be used for django app testing. I like py.test --pdb post-mortem feature.
This has most likely been fixed.
setup_environadds the parent directory to the class (and [5696] made that a bit more solid).