【发布时间】:2013-10-08 13:47:31
【问题描述】:
我知道如何使用 django 运行特定的测试类:python manage.py test MyApp.MyTestClass。
我想做的是相反的:运行所有测试,除了一个特别的。
在我看来,这看起来像这样:python manage.py test --ignore=MyApp.MyTestClass
有没有简单的方法?
编辑:额外的好处是仍然能够手动运行测试(使用第一个命令)。
【问题讨论】:
我知道如何使用 django 运行特定的测试类:python manage.py test MyApp.MyTestClass。
我想做的是相反的:运行所有测试,除了一个特别的。
在我看来,这看起来像这样:python manage.py test --ignore=MyApp.MyTestClass
有没有简单的方法?
编辑:额外的好处是仍然能够手动运行测试(使用第一个命令)。
【问题讨论】:
test 命令没有内置的忽略选项。
但您可以在要排除的类中使用 @skip 或 @skipIf 装饰器:http://docs.python.org/2.7/library/unittest.html#unittest.skipIf
import unittest
@unittest.skip("skip the test")
class MyTestClass(TestCase):
...
【讨论】:
测试命令默认没有忽略选项。你可以试试django-ignoretests。您可以使用安装它
pip install django-ignoretests
您可以通过将应用包含在IGNORE_TESTS 中来忽略应用,如下所示:
IGNORE_TESTS = (
# Apps to ignore. example : 'django.contrib.auth',
)
【讨论】: