在 PyCharm 中运行 Django 测试 [英] Running Django tests in PyCharm
本文介绍了在 PyCharm 中运行 Django 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 PyCharm 中运行一个简单的 Django 测试,但由于以下堆栈跟踪而失败-
I am trying to run a simple Django test in PyCharm, but its failing with the following stack trace-
/home/ramashishb/local/pyenv/testenv/bin/python /opt/pycharm-3.0.2/helpers/pycharm/django_test_manage.py test snippets.SimpleTest.test_simple /home/ramashishb/mine/learn/django-rest/django-rest-tutorial
Testing started at 4:37 PM ...
Traceback (most recent call last):
File "/opt/pycharm-3.0.2/helpers/pycharm/django_test_manage.py", line 18, in <module>
import django_test_runner
File "/opt/pycharm-3.0.2/helpers/pycharm/django_test_runner.py", line 14, in <module>
from django.test.testcases import TestCase
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/home/ramashishb/local/pyenv/testenv/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/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 6, in <module>
from django.middleware.csrf import rotate_token
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/middleware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/core/cache/__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/ramashishb/local/pyenv/testenv/lib/python2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.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.
Process finished with exit code 1
测试在控制台上运行良好 - ./manage.py run test
在执行测试之前似乎没有设置什么?
The test runs fine on console using- ./manage.py run test
It looks like things are not setup before executing the tests?
有什么想法吗?
谢谢,拉姆
推荐答案
转到菜单 file >设置 >Django Support
并选择正确的设置文件.
Go to menu file > settings > Django Support
and select correct settings file.
这篇关于在 PyCharm 中运行 Django 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文