12

我知道如何使用 django 运行特定的测试类:python manage.py test MyApp.MyTestClass

我想做的是相反的:运行每一个测试,除了一个特别的。在我看来,这看起来像这样:python manage.py test --ignore=MyApp.MyTestClass 有一个简单的方法吗?

编辑:额外的好处是仍然能够手动运行测试(使用第一个命令)。

4

2 回答 2

19

test命令没有内置的忽略选项。

但是您可以在要排除的类中使用@skipor装饰器:http: //docs.python.org/2.7/library/unittest.html#unittest.skipIf@skipIf

 import unittest

 @unittest.skip("skip the test")
 class MyTestClass(TestCase):
 ...
于 2013-10-02T08:46:22.923 回答
4

测试命令默认没有忽略选项。你可以试试django-ignoretests。您可以使用安装它

pip install django-ignoretests

您可以通过将它们包含在以下内容中来忽略应用程序IGNORE_TESTS

IGNORE_TESTS = (
    # Apps to ignore. example : 'django.contrib.auth',
)
于 2013-10-02T08:47:35.807 回答