gpt4 book ai didi

python - Nose 测试给出 "Improperly Configured"错误

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

我正在学习使用 django-nose,但我在设置它时遇到了问题。

./manage.py test 工作正常。但是 nosetests 没有。

我已将 django_nose 添加到 INSTALLED_APPS 并设置 TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'。它仍然在引发 ImproperlyConfigured

我试过谷歌搜索,但这不是一个常见问题,或者我一直在使用错误的查询。那里没有运气。

$ nosetests

EE
======================================================================
ERROR: Failure: ImproperlyConfigured (Requested setting CACHES, 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 "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
addr.filename, addr.module)
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/<path/to/app>/tests.py", line 1, in <module>
from django.test import TestCase
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/test/client.py", line 11, in <module>
from django.contrib.auth import authenticate, login, logout, get_user_model
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 6, in <module>
from django.middleware.csrf import rotate_token
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/middleware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/core/cache/__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/ubuntu/virtualenv/python2.7/local/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

最佳答案

@dirn 回答了问题但留下了评论..

我不应该直接运行 nosetests,而应该使用 python manage.py test 并让 python 为我调用 nose。

关于python - Nose 测试给出 "Improperly Configured"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21764607/

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