Opened 14 years ago

Closed 14 years ago

#6255 closed (fixed)

setup_environ(company.django.settings) won't work

Reported by: trebor74hr@… 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



I had problem with using 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\ i have:

    from import setup_environ
    import company.django.settings as settings

>   from django.test.client import Client

but it reports error (django 0.96):

        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\>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 ( 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.

Change History (1)

comment:1 Changed 14 years ago by Chris Beaven

Resolution: fixed
Status: newclosed

This has most likely been fixed. setup_environ adds the parent directory to the class (and [5696] made that a bit more solid).

Note: See TracTickets for help on using tickets.
Back to Top