This playbook provides examples of running Django tests at different levels (module, class, and function) using different configurations.
- Python Environment:
/root/miniconda3/envs/django_env/bin/python
- Test Runner:
tests/runtests.py
- Default Settings:
test_sqlite
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel.RemoteTestResultTest.test_picklable
This runs a specific test function within a test class.
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel.RemoteTestResultTest
This runs all test functions within a specific test class.
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel
This runs all test classes within a module.
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --verbosity=2 --settings=test_sqlite test_runner
Verbosity levels:
- 0: minimal output
- 1: normal output (default)
- 2: verbose output
- 3: very verbose output (shows individual test names)
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --parallel=2 --settings=test_sqlite admin_views
This runs tests in parallel using multiple processes.
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel.RemoteTestResultTest.test_picklable
Results:
- Total tests: 1
- Passed: 1
- Skipped: 0
- Failed: 0
- Time taken: ~0.005s Notes: Example of running a single test function
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel.RemoteTestResultTest
Results:
- Total tests: 13
- Passed: 7
- Skipped: 6
- Failed: 0
- Time taken: ~0.010s Notes: Example of running all tests in a class
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite test_runner.test_parallel
Results:
- Total tests: 17
- Passed: 11
- Skipped: 6
- Failed: 0
- Time taken: ~0.010s Notes: Example of running all tests in a module
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --verbosity=2 --settings=test_sqlite db_functions.tests
Results:
- Total tests: ~350
- Passed: ~350
- Skipped: 0
- Failed: 0 Notes: Tests database functions and transformations
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --verbosity=2 --settings=test_sqlite template_tests.test_context
Results:
- Total tests: ~25
- Passed: ~25
- Skipped: 0
- Failed: 0 Notes: Tests template context functionality including RequestContext
Command:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite forms_tests.tests.test_forms
Results:
- Total tests: ~270
- Passed: ~147
- Skipped: ~123
- Failed: 0 Notes: Tests form functionality and validation
- Test counts may vary slightly between Django versions
- Some tests may be skipped if optional dependencies are not installed (like tblib for test_runner tests)
- Use
--verbosity=3
to see individual test names when debugging - Always run tests from the project root directory
- The test database is automatically created and destroyed for each test run
- If tests are skipped due to missing dependencies, install them using pip:
/root/miniconda3/envs/django_env/bin/python -m pip install tblib
- If you get database errors, ensure the test database can be created:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --settings=test_sqlite check
- For memory issues with large test suites, try running tests in sequence:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --parallel=1
To find specific test names for running individual tests:
- Run the module with verbosity 3:
/root/miniconda3/envs/django_env/bin/python tests/runtests.py --verbosity=3 --settings=test_sqlite module_name
- Look for the test names in the output
- Use the full path: module.class.test_name