zoukankan      html  css  js  c++  java
  • pytest(6):ordering控制用例的执行顺序

    前言

      pytest框架在运行测试用例时,有时并不是完全按照顺序进行执行的, 是乱序的,因此有时我们想指定用例的顺序时可以使用pytest-order插件。

    安装方式:  

    pip install pytest-ordering

    使用方法:

      在指定的用例方法前加上装饰器 @pytest.mark.run(order=[num])  ,设置num值,num越小越先执行。

     1 # Author xuejie zeng
     2 # encoding utf-8
     3 
     4 import pytest
     5 
     6 @pytest.mark.run(order=2)
     7 def test_a():
     8     print("我是用例a")
     9     assert True
    10 
    11 @pytest.mark.run(order=1)
    12 def test_b():
    13     print("我是用例b")
    14     assert True

    运行结果:

    1 collected 2 items                                                                                                                                         
    2 
    3 test-or.py::test_b 我是用例b
    4 PASSED
    5 test-or.py::test_a 我是用例a
    6 PASSED

    也可以加负值,负值越小越先执行

     1 # Author xuejie zeng
     2 # encoding utf-8
     3 
     4 import pytest
     5 
     6 @pytest.mark.run(order=-2)
     7 def test_a():
     8     print("我是用例a")
     9     assert True
    10 
    11 @pytest.mark.run(order=-1)
    12 def test_b():
    13     print("我是用例b")
    14     assert True
    15 
    16 @pytest.mark.run(order=-4)
    17 def test_c():
    18     print("我是用例c")
    19     assert True

    运行结果:

    1 collected 3 items                                                                                                                                         
    2 
    3 test-or.py::test_c 我是用例c
    4 PASSED
    5 test-or.py::test_a 我是用例a
    6 PASSED
    7 test-or.py::test_b 我是用例b
    8 PASSED

    关注个人公众号:测试开发进阶之路

      

  • 相关阅读:
    在客户端模拟调用srv和topic
    直流电机测试标准
    vue项目修改host实现地址代理,实现一键登录
    小程序 日期格式化
    ES6学习笔记之async函数
    ES6学习笔记之promise
    ES6学习笔记之箭头函数
    ES6学习笔记之var,let,const
    axios post后台接收不到参数
    vue-cli2配置scss遇到的各种坑
  • 原文地址:https://www.cnblogs.com/zengxuejie/p/13679119.html
Copyright © 2011-2022 走看看