首页 > 其他分享 >【pytest】命令行参数-durations统计用例运行时间

【pytest】命令行参数-durations统计用例运行时间

时间:2022-08-18 23:01:09浏览次数:57  
标签:case register durations py 用例 pytest call test login

  • 前言:写完一个项目的自动化用例之后,发现有些用例运行较慢,影响整体的用例运行速度,于是领导说找出运行慢的那几个用例优化下。--durations 参数可以统计出每个用例运行的时间,对用例的时间做个排序。

  • pytest -h 查看命令行参数,关于 --durations=N 参数的使用方式

    • --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=N,N为0 的时候显示全部用例的运行时间

1.02s call     case/demo/test_demo.py::Test_class::test_001
1.01s call     case/demo/test_demo.py::Test_class::test_001
1.01s call     case/demo/test_demo.py::Test_class::test_002
1.01s call     case/demo/test_demo.py::Test_class::test_002
1.00s call     case/demo/test_demo.py::test_003
1.00s call     case/demo/test_demo.py::test_003
0.56s call     case/goods/test_goods_flow.py::test_good_01
0.54s call     case/register/test_register.py::test_register_2
0.44s call     case/register/test_register.py::test_register
0.34s call     case/goods/test_goods_flow.py::test_good_01
0.31s call     case/register/test_register.py::test_register_2
0.26s call     case/login/test_login.py::test_login_case[test_input1-expected1]
0.26s call     case/login/test_login.py::test_login_case[test_input1-expected1]
0.25s call     case/login/test_login.py::test_login_case[test_input3-expected3]
0.25s call     case/login/test_login.py::test_login_case[test_input3-expected3]
0.23s setup    case/register/test_register.py::test_register
0.23s setup    case/register/test_register.py::test_register_2
0.22s setup    case/goods/test_goods_flow.py::test_good_01
0.22s call     case/login/test_login.py::test_login_case[test_input0-expected0]
0.22s call     case/login/test_login.py::test_login_case[test_input0-expected0]
0.21s call     case/register/test_register.py::test_register
0.19s call     case/login/test_login.py::test_login_case[test_input2-expected2]
0.19s call     case/login/test_login.py::test_login_case[test_input2-expected2]

(7 durations < 0.005s hidden.  Use -vv to show these durations.)
  • 用例运行的时候会经历3个阶段:setup,call,teardown。call就是测试用例,setup和teardown就是用例的fixture部分。

  • --durations=3,筛选出运行时间最慢的3条用例

标签:case,register,durations,py,用例,pytest,call,test,login
From: https://www.cnblogs.com/xwltest/p/16600449.html

相关文章