运行 django 中带有 python unittest 的特定测试用例

running specific test case with python unittest in django

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

我也可以运行:

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

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

我的 class 会是这样的:

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

你试过了吗

wagtail.wagtailcore.tests.TestPagePrivacy.test_anonymous_user_must_authenticate

看起来答案是:

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

so-目录/文件名/class名称/测试名称