【发布时间】:2017-04-06 16:23:33
【问题描述】:
在 PyCharm 中运行测试时遇到问题。
manage.py test 工作正常。
但是如果我在 PyCharm Django Test 中运行测试会出现以下错误:
AttributeError: 'module' object has no attribute 'ROOT_URLCONF'
Django 测试运行\调试配置:
DJANGO_SETTINGS_MODULE=project.settings.test
Django 首选项
设置:project/settings/test.py
管理脚本:project/manage.py
测试
from django.test import SimpleTestCase
from rest_framework import status
class AccountTestCase(SimpleTestCase):
def test_current_account(self):
url = '/api/accounts/current/'
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_301_MOVED_PERMANENTLY)
堆栈跟踪
Error
packages/django/core/handlers/base.py", line 113, in get_response
urlconf = settings.ROOT_URLCONF
File "/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
return getattr(self._wrapped, name)
File "/lib/python2.7/site-packages/django/conf/__init__.py", line 173, in __getattr__
return getattr(self.default_settings, name)
AttributeError: 'module' object has no attribute 'ROOT_URLCONF'
不胜感激。
【问题讨论】:
-
你见过this question/answer吗?
-
是的,如果我在终端中运行测试它可以工作,这与我应该配置 PyCharm 的方式有关。