Sunday, June 9, 2013

Got a really weird error when I tried to setup a django test environment:

Type "help", "copyright", "credits" or "license" for more information.
>>> from django.test.utils import setup_test_environment
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\django\test\__init__.py", line 5, in <modu
le>
    from django.test.client import Client, RequestFactory
  File "C:\Python27\lib\site-packages\django\test\client.py", line 21, in <modul
e>
    from django.db import close_connection
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in __ge
tattr__
    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in _set
up
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but se
ttings are not configured. You must either define the environment variable DJANG
O_SETTINGS_MODULE or call settings.configure() before accessing settings.

The issue is django does not know what you are working on.  This resolved it:

C:\Users\Chris\Documents\django_dev\mysite>python manage.py shell
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.test.utils import setup_test_environment
>>>

I guess that is a django interactive shell?

No comments:

Post a Comment