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