Skip to content

Instantly share code, notes, and snippets.

@ostrokach
Created July 10, 2019 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostrokach/fc5bae0893f29be0c669ccb2b06c8ec8 to your computer and use it in GitHub Desktop.
Save ostrokach/fc5bae0893f29be0c669ccb2b06c8ec8 to your computer and use it in GitHub Desktop.
Print run-time statistics for every test
import unittest
from cProfile import Profile
from pstats import Stats
def MyTest(unittest.TestCase):
def setUp(self):
"""init each test"""
self.pr = Profile()
self.pr.enable()
def tearDown(self):
"""finish any test"""
p = Stats(self.pr)
p.strip_dirs()
p.sort_stats('cumtime')
p.print_stats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment