引言:
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'])