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-后置

上一篇:Django同步数据库


下一篇:django 基础1