gpt4 book ai didi

python - NoseTests 的基本设置

转载 作者:太空宇宙 更新时间:2023-11-04 03:55:27 24 4
gpt4 key购买 nike

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 服务器或工头在本地正常运行我的应用程序。我错过了什么?

最佳答案

那是因为nose没有办法自己找到settings模块。您应该尝试插入 django-nose

关于python - NoseTests 的基本设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18819181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com