【问题标题】:running specific test case with python unittest in django在 django 中使用 python unittest 运行特定的测试用例
【发布时间】:2018-03-24 18:37:41
【问题描述】:

我有一组可以成功运行的单元测试:./runtests.py wagtail.wagtailcore.tests

我也可以跑:

./runtests.py wagtail.wagtailcore.tests.test_page_privacy

但如果我只想执行其中一个,我会收到 'module' object has no attribute [test_case_name] 的错误

我的课是这样的:

class TestPagePrivacy(TestCase):
  def test_anonymous_user_must_authenticate(self):

所以我想你可以说:./runtests.py wagtail.wagtailcore.tests.test_page_privacy.test_anonymous_user_must_authenticate

为什么这不起作用?

来自 django 文档:

https://docs.djangoproject.com/en/1.11/topics/testing/overview/#running-tests

# Run just one test method
$ ./manage.py test animals.tests.AnimalTestCase.test_animals_can_speak

【问题讨论】:

  • 我猜你需要把测试用例类名放在中间
  • 抱歉,修改了我的帖子 - 这不起作用。

标签: python django unit-testing python-unittest wagtail


【解决方案1】:

看起来答案是:

./runtests.py wagtail.wagtailcore.tests.test_page_privacy.TestPagePrivacy.test_anonymous_user_must_authenticate

so - 目录/文件名/类名/测试名

【讨论】:

  • 这给了我输出 Ran 0 tests,使用 Django 2.2.0。
  • @Igettäjä Wagtail 2 中更改的模块路径 - 现在等效命令为:./runtests.py wagtail.core.tests.test_page_privacy.TestPagePrivacy.test_anonymous_user_must_authenticate
【解决方案2】:

你试过了吗

wagtail.wagtailcore.tests.TestPagePrivacy.test_anonymous_user_must_authenticate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-28
    • 2014-02-27
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多