如何使用nosetests测量python单元测试的执行时间?

kam*_*mal 27 python nosetests

有没有办法计算由nosetests运行的单个Python测试的执行时间?

Noa*_*oah 27

您可以尝试在此处发布的鼻子插件:https://github.com/mahmoudimus/nose-timer(或通过pip/PyPi获得).您还可以使用内置插件--with-profile进行更严格的分析.

  • nosetests -s --with-xunit --with-profile`find.-name"*test.py"`用法:nosetests [options] nosetests:错误:没有这样的选项: - with-profile (4认同)

Jon*_*ley 9

或者:

python -m cProfile -o profile.out `which nosetests` .
Run Code Online (Sandbox Code Playgroud)

可以使用例如runsnakerun查看输出,这使得在视觉上非常明显地表现出性能问题.(例如,它可能是许多测试间接调用的常用方法)