Вопрос

The documentation for NoseTests seems really straightforward, but I can't find the answer to the initial setup anywhere. I've done pip install nosetests and it went fine, but when I type "nosetests" at the root of my django project, I get the following:

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.

Clearly it's not picking up settings across the Django app, but it's not clear why - I'm able to run my app fine locally with python manage.py server or with foreman. What did I miss?

Это было полезно?

Решение

That's because nose has no way of finding the settings module by itself. You should try plugging in django-nose

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top