pytest- adjustment execution order of test cases

Scene: not taken into account when performing natural order, or would like to change the order of execution, such as increasing the use case data must be executed, and then delete the use cases. The default is the test case execution order by name.

 

• Resolution:
• Installation: pip install pytest-ordering

• Add the following decorator on the test method

•@Pytest.mark.last --- The last execution
• @ pytest.mark.run (order = 1) --- the first of several execution

 

pytest default to alphabetical order of execution

 

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

 

Guess you like

Origin www.cnblogs.com/QaStudy/p/11567039.html