Pytest---控制用例的执行顺序
pytest加载所有的用例都是乱序的,如果想指定用例的顺序,可以使用pytest-ordering插件,指定用例的执行顺序只需要在测试用例的方法前面加上装饰器@pytest.mark.run(order=[num])设置order的对应的num值,它就可以按照num的大小顺序来执行。
安装
pip install pytest-ordering
例子
import pytest class TestDemo: @pytest.mark.run(order=-2) def test_demo1(self): print('this is test_demo1') @pytest.mark.run(order=-1) def test_demo2(self): print('this is test_demo2') @pytest.mark.run(order=2) def test_demo3(self): print('this is test_demo3') @pytest.mark.run(order=1) def test_demo4(self): print('this is test_demo4')

从上边的结果可以看出运行的顺序是 order=2,order=1,order=-2,order=-1

浙公网安备 33010602011771号