2

NoseTests 的文档看起来非常简单,但我在任何地方都找不到初始设置的答案。我已经完成了 pip install 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 服务器或工头在本地正常运行我的应用程序。我错过了什么?

4

1 回答 1

2

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

于 2013-09-16T05:35:28.667 回答