【问题标题】:Error running Django tests运行 Django 测试时出错
【发布时间】:2016-06-20 17:57:45
【问题描述】:

我正在尝试运行 Django 测试(1.8 版)

但我得到了这个错误

from django.test import TestCase

class JobTypesResourceTest (TestCase):
    def setUp(self):
        TestCase.setUp(self)
    def test_basicGet(self):
        return True

Traceback (most recent call last):
  File "C:\Users\user\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\runfiles.py", line 234, in <module>
    main()
  File "C:\Users\user\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\runfiles.py", line 78, in main
    return pydev_runfiles.main(configuration)  # Note: still doesn't return a proper value.
  File "C:\Users\user\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydev_runfiles.py", line 835, in main
    PydevTestRunner(configuration).run_tests()
  File "C:\Users\user\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydev_runfiles.py", line 793, in run_tests
    MyDjangoTestSuiteRunner(run_tests).run_tests([])
  File "C:\Users\user\.p2\pool\plugins\org.python.pydev_4.4.0.201510052309\pysrc\pydev_runfiles.py", line 813, in run_tests
    raise AssertionError("Unable to run suite with DjangoTestSuiteRunner because it couldn't be imported.")
AssertionError: Unable to run suite with DjangoTestSuiteRunner because it couldn't be imported.

我是否缺少 python 库?

【问题讨论】:

  • 您的代码中有错字:不是true,而是True
  • 谢谢我已经修好了,所以这不是问题
  • 你的测试课对我有用。你有追溯吗?
  • 您好,我使用了您在创建新 Django 项目时获得的默认文件层次结构,并且我正在使用 Eclipse run as pyunit 运行
  • 看来你应该配置 Pyunit 测试运行器。不过最好不要使用IDE。 :-°

标签: django eclipse pydev django-testing python-unittest


【解决方案1】:

不要使用上下文菜单“运行方式”->“Python 单元测试”。改用项目的上下文菜单 'Django' -> 'Run Django Tests (manage.py test)'。

为 Django 测试创建启动配置,复制运行 Django 项目的启动配置(在 'Run as' -> 'PyDev: Django' 之后自动创建) 并将程序参数从“runserver”更改为“test”。

【讨论】:

    【解决方案2】:

    感谢您的帮助。看起来我运行测试错误。我正在使用 Eclipse-> run as pyunit 选项,看起来像是在使用旧代码。当我使用manage.py test运行时正在工作

    【讨论】:

      【解决方案3】:

      您的TEST_RUNNER 设置设置为django.test.simple.DjangoTestSuiteRunner 或其子类。

      django.test.simple.DjangoTestSuiteRunnerdeprecated in Django 1.6removed in Django 1.8

      由于您使用的是 Eclipse,我认为 this 对您来说是准确的。

      【讨论】:

      • 我没有对 Django 1.8 做任何更改,你可以看到我使用的唯一代码就是我上面写的,所以我没有写任何使用 DjangoTestSuiteRunner 的代码
      • 您的TEST_RUNNER 设置是什么? (如果设置)请提供完整的回溯,正如@soon 所说。
      • 我没有设置测试运行器,并且已经添加了堆栈跟踪
      • 你没有,但你的 IDE 做到了。您必须对其进行配置以使用正确的测试运行器。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多