Is there a way to time the execution time of individual Python tests which are run by nosetests ?
Asked
Active
Viewed 8,774 times
2 Answers
28
You might try the nose plug-in posted here: https://github.com/mahmoudimus/nose-timer (or available via pip / PyPi). You can also use the built-in plugin --with-profile
to do more serious profiling.
-
4nosetests -s --with-xunit --with-profile `find . -name "*test.py"` Usage: nosetests [options] nosetests: error: no such option: --with-profile – kamal Mar 30 '11 at 03:59
-
hrm, works for me. Are you running the latest version of nosetests? (seems to be 1.0.0) See here for info about profiling: http://somethingaboutorange.com/mrl/projects/nose/1.0.0/plugins/prof.html – Noah Mar 30 '11 at 14:23
-
Try `python -c 'from hotshot import stats'`, I think that will break on you and tell you to install the python-profiler package. – Chris Wesseling Aug 08 '11 at 04:10
-
The hotshot profiler that nose uses by default isn't really supported anymore, I believe. I wrote a plugin to use cProfile instead, which you can find here: http://pypi.python.org/pypi/nose-cprof/0.1-0 – Marc Jul 17 '12 at 19:58
-
nose-cprof not working for me. pip install looks fine, but the flag seems to be not found: no such option: --with-cprofile. --with-profile seems to work for me thoug – Priyeshj Jul 13 '16 at 20:07
10
Alternatively:
python -m cProfile -o profile.out `which nosetests` .
The output from can be viewed using, for example, runsnakerun, which makes it visually very obvious where your performance problems are. (e.g. it might be in a common method that many tests indirectly call)

Ryan Ginstrom
- 13,915
- 5
- 45
- 60

Jonathan Hartley
- 15,462
- 9
- 79
- 80