简体   繁体   English

在django中使用python unittest运行特定的测试用例

[英]running specific test case with python unittest in django

I have a set of unit tests that I can successfully run with: ./runtests.py wagtail.wagtailcore.tests 我有一套可以成功运行的单元测试: ./runtests.py wagtail.wagtailcore.tests

I can also run: 我也可以运行:

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

But if I want to execute just one of them, I get an error that 'module' object has no attribute [test_case_name] 但是,如果我只想执行其中一个,我得到一个错误, 'module' object has no attribute [test_case_name]

My class would be something like: 我的课将是这样的:

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

so I would think you could just say: ./runtests.py wagtail.wagtailcore.tests.test_page_privacy.test_anonymous_user_must_authenticate 所以我想你可以这样说: ./runtests.py wagtail.wagtailcore.tests.test_page_privacy.test_anonymous_user_must_authenticate

Why doesn't this work? 为什么这不起作用?

From the django docs: 来自django文档:

https://docs.djangoproject.com/en/1.11/topics/testing/overview/#running-tests 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

Looks like the answer is: 看起来答案是:

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

So - directory / file name / class name / test name 所以 - 目录/文件名/类名/测试名

你有没有尝试过

wagtail.wagtailcore.tests.TestPagePrivacy.test_anonymous_user_must_authenticate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM