Django Limit the number of tests executed


Example

It is possible to limit the tests executed by manage.py test by specifying which modules should be discovered by the test runner:

# 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

If you want to run a bunch of tests you can pass a pattern of filenames. For example, you may want to run only tests that involving of your models:

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

OK

Finally, it is possible to stop the test suite at the first fail, using --failfast. This argument allows to get quickly the potential error encountered in the suite:

$ 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)