NoseTests的基本设置

时间:2013-09-16 01:15:27

标签: python django nose nosetests

NoseTests的文档似乎非常简单,但我无法在任何地方找到初始设置的答案。我做了pip安装nosetests它很好,但是当我在我的django项目的根目录下输入“nosetests”时,我得到以下内容:

ERROR: Failure: ImproperlyConfigured (Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/aronchick/Code/ayafi/pages/tests.py", line 1, in <module>
    from django.test import TestCase
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module>
    from django.test.client import Client, RequestFactory
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/django/test/client.py", line 21, in <module>
    from django.db import close_connection
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/Users/aronchick/Code/ayafi/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

显然,它并没有在Django应用程序中获取设置,但不清楚为什么 - 我可以使用python manage.py服务器或工头在本地运行我的应用程序。我错过了什么?

1 个答案:

答案 0 :(得分:2)

那是因为鼻子无法自己找到设置模块。您应该尝试插入django-nose