Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get python unit test duration in seconds

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.

like image 518
williamtroup Avatar asked Aug 20 '12 08:08

williamtroup


1 Answers

UPDATED, thanks to @Centralniak's comment.

How about simple

from datetime import datetime

tick = datetime.now()

# run the tests here   

tock = datetime.now()   
diff = tock - tick    # the result is a datetime.timedelta object
print(diff.total_seconds())
like image 104
Zaur Nasibov Avatar answered Sep 21 '22 02:09

Zaur Nasibov