當(dāng)前位置:
首頁 >
Pytest-ordering自定义用例执行顺序
發(fā)布時(shí)間:2025/3/15
48
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Pytest-ordering自定义用例执行顺序
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我們一般在做自動(dòng)化測(cè)試時(shí),用例設(shè)計(jì)之間應(yīng)該是可以相互獨(dú)立執(zhí)行的,沒有一定的前后依賴關(guān)系的,如果我們真的有前后依賴,想指定用例的先后順序,可以用到pytest-ordering插件解決這個(gè)問題
1、安裝依賴包
pip install pytest-ordering
2、運(yùn)用
用例方法上添加裝飾器@pytest.mark.run(order=2),用例執(zhí)行順序會(huì)以order值大小升序去調(diào)用執(zhí)行
3、先按Pytest默認(rèn)執(zhí)行順序(根據(jù)用例的先后順序)先執(zhí)行了用例1(test_login_01)再執(zhí)行了用例2(test_login_02)
#!/usr/bin/env python # _*_coding:utf-8_*_ import pytestclass Test(object):def test_login_01(self):"""用例1"""print('執(zhí)行用例test_login_01斷言1')pytest.assume(1 == 1)print('執(zhí)行用例test_login_01斷言2')pytest.assume(2 == 2)def test_login_02(self):"""用例2"""print('執(zhí)行用例test_login_02斷言1')pytest.assume(3 == 3)print('執(zhí)行用例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 收集的測(cè)試用例:[<Function test_login_01>, <Function test_login_02>] collected 2 itemstest_C_01.py 執(zhí)行用例test_login_01斷言1 執(zhí)行用例test_login_01斷言2 .執(zhí)行用例test_login_02斷言1 執(zhí)行用例test_login_02斷言2 .============================== 2 passed in 0.04s ==============================Process finished with exit code 04、設(shè)置了用例先后順序?yàn)閑st_login_01(@pytest.mark.run(order=2))、test_login_02(@pytest.mark.run(order=1)),調(diào)用后先執(zhí)行了用例2(test_login_02)再執(zhí)行了用例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('執(zhí)行用例test_login_01斷言1')pytest.assume(1 == 1)print('執(zhí)行用例test_login_01斷言2')pytest.assume(2 == 2)@pytest.mark.run(order=1)def test_login_02(self):"""用例2"""print('執(zhí)行用例test_login_02斷言1')pytest.assume(3 == 3)print('執(zhí)行用例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 收集的測(cè)試用例:[<Function test_login_01>, <Function test_login_02>] collected 2 itemstest_C_01.py 執(zhí)行用例test_login_02斷言1 執(zhí)行用例test_login_02斷言2 .執(zhí)行用例test_login_01斷言1 執(zhí)行用例test_login_01斷言2 .============================== 2 passed in 0.06s ==============================Process finished with exit code 0?
總結(jié)
以上是生活随笔為你收集整理的Pytest-ordering自定义用例执行顺序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【工具】FTP软件FileZilla下载
- 下一篇: 全网都在看的Fiddler、mitmpr