Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see which tests were run during Django's manage.py test command

After tests execution is finished using Django's manage.py test command only number of passed tests is printed to the console.

(virtualenv) G:\Project\>python manage.py test Creating test database for alias 'default'... True .. ---------------------------------------------------------------------- Ran 2 tests in 0.017s  OK Destroying test database for alias 'default'... 

Is there any way to see:

  1. which tests were actually executed
  2. from what module
  3. in what order

I haven't found any solution in the doc.

like image 529
Mariusz Jamro Avatar asked Feb 01 '14 16:02

Mariusz Jamro


People also ask

What does manage PY test do?

Running python manage.py test is the right way to run all the tests in your projects at once, your error is caused by something else. I think your problem is caused because you may have a tests folder within your tests folder, which is confusing unittest.

What order Django tests are run?

Order in which tests are executedAll TestCase subclasses are run first. Then, all other Django-based tests (test cases based on SimpleTestCase , including TransactionTestCase ) are run with no particular ordering guaranteed nor enforced among them.

How do I run a specific test case in Django?

You need to open you init.py and import your tests. Show activity on this post. If you want to run a test case class which has the path <module_name>/tests/test_views.py , you can run the command python manage.py test <module_name>. tests.


1 Answers

You can pass -v 2 to the test command:

python manage.py test -v 2 

After running this command you'll get something like this (I'm using django 2, feel free to ignore migrations/database stuff):

Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')... Operations to perform:   Synchronize unmigrated apps: messages, staticfiles   Apply all migrations: admin, auth, contenttypes, sessions Synchronizing apps without migrations:   Creating tables...    Running deferred SQL... Running migrations:   Applying contenttypes.0001_initial... OK   ...   Applying sessions.0001_initial... OK System check identified no issues (0 silenced). test_equal_hard (polls.tests.TestHard) ... ok      <--------+ test_equal_simple (polls.tests.TestSimple) ... ok  <--------+                                                             |                                                             |            That's your tests!  >----------------------------+ 

By the way, v stands for verbosity (You can also use --verbosity=2):

python manage.py test --verbosity=2 

Here's the excerpt from the python manage.py test --help:

-v {0,1,2,3}, --verbosity {0,1,2,3}

Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output

like image 147
Nigel Tufnel Avatar answered Sep 25 '22 06:09

Nigel Tufnel