我正在使用py.test在CI服务器上运行单元测试。测试使用通过网络获取的外部资源。有时测试运行程序花费的时间过长,导致测试运行程序被中止。我不能在本地重复这个问题。
有没有办法让py。测试打印出(慢)测试的执行时间,因此确定有问题的测试变得更容易?
我正在使用py.test在CI服务器上运行单元测试。测试使用通过网络获取的外部资源。有时测试运行程序花费的时间过长,导致测试运行程序被中止。我不能在本地重复这个问题。
有没有办法让py。测试打印出(慢)测试的执行时间,因此确定有问题的测试变得更容易?
你可以用持续时间传递这个数字
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
参考地址:https://medium.com/@brianokken/pytest-duration -0-show-all-times-for-tests-and setup-and-teardown-848dccac85db
或者:https://docs.pytest.org/en/latest/usage.html profiling-test-execution-duration