How do I measure the execution time of python unit tests with nosetests?

Question:

Is there a way to time the execution time of individual Python tests which are run by nosetests ?

Asked By: kamal

||

Answers:

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.

Answered By: Noah

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)

Answered By: Jonathan Hartley
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.