PyCharm Django 测试运行程序无法看到 django.sites(运行时错误)
PyCharm Django test runner can't see django.sites (Runtime Error)
当我 运行 manage.py test
一切正常时,但是如果 运行 使用 PyCharm Django 测试进行测试,它会给我以下错误:
Error
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: order_form.tests
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/home/vagrant/project/order_form/tests.py", line 2, in <module>
from .models import Order
File "/home/vagrant/project/order_form/models.py", line 3, in <module>
from cms.models.pluginmodel import CMSPlugin
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/__init__.py", line 3, in <module>
from .pagemodel import * # nopyflakes
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/pagemodel.py", line 6, in <module>
from django.contrib.sites.models import Site
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
是的,我在INSTALLED_APPS中启用了'django.contrib.sites'
并且设置了SITE_ID。
有什么想法吗?
我创建了本地 virtualenv 并安装了相同的要求——测试工作正常。
谢谢大家提意见
当我 运行 manage.py test
一切正常时,但是如果 运行 使用 PyCharm Django 测试进行测试,它会给我以下错误:
Error
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: order_form.tests
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/home/vagrant/project/order_form/tests.py", line 2, in <module>
from .models import Order
File "/home/vagrant/project/order_form/models.py", line 3, in <module>
from cms.models.pluginmodel import CMSPlugin
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/__init__.py", line 3, in <module>
from .pagemodel import * # nopyflakes
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/pagemodel.py", line 6, in <module>
from django.contrib.sites.models import Site
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
是的,我在INSTALLED_APPS中启用了'django.contrib.sites'
并且设置了SITE_ID。
有什么想法吗?
我创建了本地 virtualenv 并安装了相同的要求——测试工作正常。
谢谢大家提意见