微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐