我正在使用py.test在CI服务器上运行单元测试.测试使用通过网络获取的外部资源.有时测试运行器需要太长时间,导致测试运行器中止.我无法在本地重复这些问题.
有没有办法让py.test打印出(慢)测试的执行时间,所以固定有问题的测试会变得更容易?
Bru*_*ira 132
我不确定这会解决您的问题,但您可以在测试套件完成后传递--durations=N打印最慢的N测试.
您可以通过传递数字 --durations
pytest --durations=0?—?Show all times for tests and setup and teardown
pytest --durations=1?—?Just show me the slowest
pytest --durations=50?—?Slowest 50, with times, … etc
Run Code Online (Sandbox Code Playgroud)
请参阅:https : //medium.com/@brianokken/pytest-durations-0-show-all-times-for-tests-and-setup-and-teardown-848dccac85db
或者:https : //docs.pytest.org/en/latest/usage.html#profiling-test-execution-duration