其他分享
首页 > 其他分享> > Pytest-命令行参数--durations的使用

Pytest-命令行参数--durations的使用

作者:互联网

--durations用于计算每个用例执行的执行时间,并进行排序

> pytest -h

--durations=N         show N slowest setup/test durations (N=0 for all).
--durations-min=N     Minimal duration in seconds for inclusion in slowest list. Default 0.005

--durations=0时,显示所有用例的执行时间

========================================================================= slowest durations =========================================================================
0.50s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_users_login
0.26s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v3_login
0.22s setup    testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data0]
0.22s call     testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register
0.21s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login
0.21s teardown testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register
0.21s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_pwd
0.18s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_username
0.17s call     testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data0]
0.10s call     testcases/goods_demo/test_v1_goods.py::TestGoods::test_v1_goods[goods_data1]

--durations=5时,显示执行时间最慢的5条用例

======================================================================== slowest 5 durations ========================================================================
0.51s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_users_login
0.27s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login
0.21s call     testcases/login_demo/test_users_login.py::TestUsersLogin::test_v1_login_username
0.21s teardown testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register
0.20s call     testcases/login_demo/test_v1_register.py::TestUserRegister::test_v1_register

注:

  call-测试用例

  setup-前置

  teardown-后置

标签:--,demo,durations,py,v1,testcases,Pytest,test,login
来源: https://www.cnblogs.com/LT-XILI/p/15830245.html