限制执行的测试数量

可以通过指定测试运行器应该发现哪些模块来限制 manage.py test 执行的测试:

# Run only tests for the app names "app1"
$ python manage.py test app1

# If you split the tests file into a module with several tests files for an app
$ python manage.py test app1.tests.test_models

# it's possible to dig down to individual test methods.
$ python manage.py test app1.tests.test_models.MyTestCase.test_something

如果要运行一堆测试,可以传递文件名模式。例如,你可能只想运行涉及模型的测试:

$ python manage.py test -p test_models*
Creating test database for alias 'default'...
.................................................Ran 115 tests in 3.869s

OK

最后,可以使用 --failfast 在第一次失败时停止测试套件。此参数允许快速获取套件中遇到的潜在错误:

$ python manage.py test app1
...F..Ran 6 tests in 0.977s

FAILED (failures=1)

$ python manage.py test app1 --failfast
...F
======================================================================
[Traceback of the failing test]Ran 4 tests in 0.372s

FAILED (failures=1)