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

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

      

  • 相关阅读:
    ThreadPoolExecutor的重要参数
    分布式系统中一致性哈希算法
    监测工具dstat
    luamysql 安装
    修改linux下系统资源限制
    linux系统资源监视工具TOP
    /etc/security/limits.conf
    lua连接mysql数据库
    query cache 的内存使用和调优
    redhat5 和redhat6 root用户不同的ulimits
  • 原文地址:https://www.cnblogs.com/zengxuejie/p/13679119.html
Copyright © 2011-2022 走看看