日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Pytest-ordering自定义用例执行顺序

發布時間:2025/3/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pytest-ordering自定义用例执行顺序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們一般在做自動化測試時,用例設計之間應該是可以相互獨立執行的,沒有一定的前后依賴關系的,如果我們真的有前后依賴,想指定用例的先后順序,可以用到pytest-ordering插件解決這個問題

1、安裝依賴包
pip install pytest-ordering

2、運用
用例方法上添加裝飾器@pytest.mark.run(order=2),用例執行順序會以order值大小升序去調用執行

3、先按Pytest默認執行順序(根據用例的先后順序)先執行了用例1(test_login_01)再執行了用例2(test_login_02)

#!/usr/bin/env python # _*_coding:utf-8_*_ import pytestclass Test(object):def test_login_01(self):"""用例1"""print('執行用例test_login_01斷言1')pytest.assume(1 == 1)print('執行用例test_login_01斷言2')pytest.assume(2 == 2)def test_login_02(self):"""用例2"""print('執行用例test_login_02斷言1')pytest.assume(3 == 3)print('執行用例test_login_02斷言2')pytest.assume(True)if __name__ == '__main__':pytest.main(['-s', 'test_C_01.py'])C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe C:/Users/admin/Desktop/AutoTest/Test/test/test_C_01.py ============================= test session starts ============================= platform win32 -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 rootdir: C:\Users\admin\Desktop\AutoTest\Test\test plugins: assume-2.2.1, ordering-0.6 收集的測試用例:[<Function test_login_01>, <Function test_login_02>] collected 2 itemstest_C_01.py 執行用例test_login_01斷言1 執行用例test_login_01斷言2 .執行用例test_login_02斷言1 執行用例test_login_02斷言2 .============================== 2 passed in 0.04s ==============================Process finished with exit code 0

4、設置了用例先后順序為est_login_01(@pytest.mark.run(order=2))、test_login_02(@pytest.mark.run(order=1)),調用后先執行了用例2(test_login_02)再執行了用例1(test_login_01)

#!/usr/bin/env python # _*_coding:utf-8_*_ import pytestclass Test(object):@pytest.mark.run(order=2)def test_login_01(self):"""用例1"""print('執行用例test_login_01斷言1')pytest.assume(1 == 1)print('執行用例test_login_01斷言2')pytest.assume(2 == 2)@pytest.mark.run(order=1)def test_login_02(self):"""用例2"""print('執行用例test_login_02斷言1')pytest.assume(3 == 3)print('執行用例test_login_02斷言2')pytest.assume(True)if __name__ == '__main__':pytest.main(['-s', 'test_C_01.py'])C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe C:/Users/admin/Desktop/AutoTest/Test/test/test_C_01.py ============================= test session starts ============================= platform win32 -- Python 3.7.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 rootdir: C:\Users\admin\Desktop\AutoTest\Test\test plugins: assume-2.2.1, ordering-0.6 收集的測試用例:[<Function test_login_01>, <Function test_login_02>] collected 2 itemstest_C_01.py 執行用例test_login_02斷言1 執行用例test_login_02斷言2 .執行用例test_login_01斷言1 執行用例test_login_01斷言2 .============================== 2 passed in 0.06s ==============================Process finished with exit code 0

?

總結

以上是生活随笔為你收集整理的Pytest-ordering自定义用例执行顺序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。