首页 > 其他 > 详细

pytest指定用例的运行顺序

时间:2020-10-05 15:20:41      阅读:150      评论:0      收藏:0      [点我收藏+]

引言:

  pytest默认是按照字母来执行执行顺序,但是多接口之间存在值引用的关系,那么我们就需要执行case的执行顺序。pytest控制case执行顺序的插件是pytest-ordering,直接用pip安装就可以了

pip install pytest-ordering

     通过装饰器的方法来控制case的执行顺序,以后会附上源码分析,demo如下

‘‘‘

pytest 执行顺序
last方法执行最后一个执行
‘‘‘
import pytest
import requests


@pytest.mark.run(order=2)
def test_baidu():
    ret=requests.get(url="http://www.baidu.com")
    print("baidu2")
@pytest.mark.run(order=1)
def test_163():
    ret=requests.get(url="http://163.com")
    print("wangyi1")

@pytest.mark.last
def test_qq():
    print(‘qq4‘)
@pytest.mark.run(order=3)
def test_aliyun():
    print("aliyun3")
if __name__ == ‘__main__‘:
    pytest.main([‘-s‘,‘test_ordering.py‘])

  

 

  

pytest指定用例的运行顺序

原文:https://www.cnblogs.com/yuan-x/p/13769938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!