【问题标题】:PyCharm Django test runner can't see django.sites (Runtime Error)PyCharm Django 测试运行器看不到 django.sites(运行时错误)
【发布时间】:2016-03-28 14:24:22
【问题描述】:

当我运行manage.py test 时,一切正常,但如果使用 PyCharm Django Tests 运行测试,则会出现以下错误:

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.

是的,我已启用'django.contrib.sites'在 INSTALLED_APPS 中并设置了 SITE_ID。

有什么想法吗?

【问题讨论】:

  • 你确定你使用的是正确的 virtualenv 吗?
  • 你在 vagrant 盒子里运行manage.py test - 显然 pycharm 项目配置为在 vagrant 内使用 venv。
  • @dahrens,是的,我在 Vagrant venv 中运行 manage.py test
  • 但是默认情况下作为python路径一部分的工作目录是在外面配置的?您可以从流浪者框中指定它吗? ...只是一个快速的想法...
  • 基于this post,您可能想使用ssh://vagrant@....定义远程流浪盒

标签: python django pycharm django-sites


【解决方案1】:

我创建了本地 virtualenv 并安装了相同的要求 - 测试可以正常工作。

谢谢大家的cmets。

【讨论】:

    猜你喜欢
    • 2018-04-20
    • 2013-12-22
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多