Go to most recent revision | Compare with Previous | Blame | View Log
"""profile_tests.py -- Profile specified tests or suitesUsage-----Profile tests in a specific module::RunPython -m profile_tests repository.tests.TestTextProfile a specific test class::RunPython -m profile_tests repository.tests.TestText.TestTextProfile a specific test method::RunPython -m profile_tests repository.tests.TestText.TestText.testAppendProfile all tests in a suite::RunPython -m profile_tests repository.tests.suiteBy default, the top 10 routines (by time consumed) will be printed,and the profile statistics will be saved in 'profile.dat'. However, ifyou'd like to query the statistics interactively, add a '-i' before'profile_tests.py' on the command line, e.g.::RunPython -i profile_tests.py repository.tests.TestTextThis will drop you to a Python interpreter prompt when the tests arefinished, and you will have a loaded 'stats' object in the variable 's'.So, to re-sort the statistics by cumulative time and print the top 20routines, you would do something like this::>>> s.sort_stats("cumulative")>>> s.print_stats(20)and a report will be displayed. For more information on generatingprofiler reports, see http://python.org/doc/current/lib/profile-stats.htmlor the 'pstats' module chapter of your Python manual."""import sysfrom run_tests import ScanningLoaderfrom unittest import mainfrom hotshot import Profilefrom hotshot.stats import loadif __name__ == '__main__':if len(sys.argv)<2 or sys.argv[1] in ('-h','--help'): # XXXprint __doc__sys.exit(2)stats_file = "profile.dat"try:Profile(stats_file).run("main(module=None, testLoader=ScanningLoader())")except SystemExit:# prevent unittest.main() from forcing an early exitpasss = load(stats_file)s.sort_stats("time")s.print_stats(10)