引言:
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‘])
原文:https://www.cnblogs.com/yuan-x/p/13769938.html