import pytest
class TestM:
@pytest.mark.run(order=-1)
def test_two(self):
pass
@pytest.mark.run(order=3)
def test_one(self):
pass
class TestL:
@pytest.mark.run(order=1)
def test_three(self):
pass
在命令行运行命令pytest -v,执行结果顺序并没有发生改变,并有告警提示如下:
test_pytest1.py::TestM::test_two PASSED [ 33%]
test_pytest1.py::TestM::test_one PASSED [ 66%]
test_pytest1.py::TestL::test_three PASSED [100%]
========================================== warnings summary ==========================================
test_pytest1.py:4
D:\PycharmProjects\test_pytest\test_pytest1.py:4: PytestUnknownMarkWarning: Unknown pytest.
mark.run - is this a typo? You can register custom marks to avoid this warning - for details, see http
s://docs.pytest.org/en/stable/mark.html
@pytest.mark.run(order=[-1])
原因:
没有安装pytest-ordering
解决方法:运行一下命令进行安装
pip install pytest-ordering
重新执行结果,执行顺序发生改变:
collected 3 items
test_pytest1.py::TestL::test_three PASSED [ 33%]
test_pytest1.py::TestM::test_one PASSED [ 66%]
test_pytest1.py::TestM::test_two PASSED [100%]
================================================ 3 passed in 0.03s ================================================