我正在使用py.test在CI服务器上运行单元测试。测试使用通过网络获取的外部资源。有时测试运行器需要太长时间,导致测试运行器中止。我无法在本地重复这些问题。
有没有办法让py.test打印出(慢)测试的执行时间,所以固定有问题的测试会变得更容易?
我不确定这会解决你的问题,但你可以通过--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
或者:https://docs.pytest.org/en/latest/usage.html#profiling-test-execution-duration