pytest-調整測試用例的執行順序


場景:未考慮按自然順序執行時,或想變更執行順序,比如增加 數據的用例要先執行,再執行刪除的用例。測試用例默認是按名 稱順序執行的。

 

• 解決:
• 安裝:pip install pytest-ordering

• 在測試方法上加下面裝飾器

•@pytest.mark.last    ---最后一個執行
• @pytest.mark.run(order=1)---第幾個執行

 

pytest默認按字母順序去執行的

 

import pytest
@pytest.mark.run(order=1)
def test_01():
print('test01')

@pytest.mark.run(order=2)
def test_02():
print('test01')
@pytest.mark.last
def test_06():
print('test01')

def test_04():
print('test01')

def test_05():
print('test01')
@pytest.mark.run(order=3)
def test_03():
print('test01')

pytest_order.py::test_01 PASSED [ 16%]test01

pytest_order.py::test_02 PASSED [ 33%]test01

pytest_order.py::test_03 PASSED [ 50%]test01

pytest_order.py::test_04 PASSED [ 66%]test01

pytest_order.py::test_05 PASSED [ 83%]test01

pytest_order.py::test_06 PASSED [100%]test01

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM