Pytest-ordering自定义用例执行顺序
生活随笔
收集整理的這篇文章主要介紹了
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 04、設置了用例先后順序為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自定义用例执行顺序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【工具】FTP软件FileZilla下载
- 下一篇: python不能安装怎么办_python