[Fixed]-Display list of all tests in a Django project

16👍

In my opinion, the more correct way is to use the actual tool for running tests. E.g. in case of nose:

./manage.py test <app> --verbosity 2 --collect-only

FYI, py.test also has --collectonly option to print tests instead of executing.

Also see:

👤alecxe

-1👍

In my case, I’m running the command with Docker, but just ignore the Docker command and get the command inside the quotes.

django.test | unittest

sudo docker compose run --rm app sh -c "python manage.py test --verbosity 2 --force-color"
(venv) ➜  recipe-app-api git:(main) ✗ sudo docker compose run --rm app sh -c "python manage.py test --verbosity 2 --force-color"
[+] Running 1/0
 ⠿ Container recipe-app-api-db-1  Running                                                                                                         0.0s
Skipping setup of unused database(s): default.
System check identified no issues (0 silenced).
test_add_numbers (app.tests.CalcTests)
Test adding number together. ... ok
test_subtract_numbers (app.tests.CalcTests)
Test subtracting numbers. ... ok
test_wait_for_db_delay (core.tests.test_commands.CommandTests)
Test waiting for database when  getting OperationalError. ... Waiting for database...
Database unvailable, waiting 1 second...
Database unvailable, waiting 1 second...
Database unvailable, waiting 1 second...
Database unvailable, waiting 1 second...
Database unvailable, waiting 1 second...
Database available!
ok
test_wait_for_db_ready (core.tests.test_commands.CommandTests)
Test waiting for database if database ready. ... Waiting for database...
Database available!
ok

----------------------------------------------------------------------
Ran 4 tests in 0.007s

OK

You can pass the verbosity or just -v parameter.
The -v parameter has more 4 options to display the test in the screen.

For more information regarding the options:

usage: manage.py test [-h] [--noinput] [--failfast] [--testrunner TESTRUNNER] [-t TOP_LEVEL] [-p PATTERN] [--keepdb] [-r] [--debug-mode] [-d]
                      [--parallel [N]] [--tag TAGS] [--exclude-tag EXCLUDE_TAGS] [--pdb] [-b] [--no-faulthandler] [--timing] [-k TEST_NAME_PATTERNS]
                      [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]
                      [test_label ...]

Leave a comment