限制執行的測試數量

可以通過指定測試執行器應該發現哪些模組來限制 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)