Get python unit test duration in seconds

Viewed 8735

Is there any way to get the total amount of time that "unittest.TextTestRunner().run()" has taken to run a specific unit test.

I'm using a for loop to test modules against certain scenarios (some having to be used and some not, so they run a few times), and I would like to print the total time it has taken to run all the tests.

Any help would be greatly appreciated.

5 Answers

Besides using datetime, you could also use time

from time import time

t0 = time()

# do your stuff here

print(time() - t0) # it will show in seconds
Related