pytest指定用例的运行顺序


引言:

  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'])

  

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM