pytest本身执行测试用例是无序的,若要按照一定的顺序,可以按照下面的方式进行:

 

先要安装该插件,pip3 install pytest-ordering,然后加上如下装饰器,既可以运行

 

1、标记于被测试函数, @pytest.mark.run(order=x)
2、根据order传入的参数来解决运行顺序
3、order值全为正数或负数时,值越小优先级越高
4、正负数同时存在时,正数优先极高
5、已标记和未标记的函数,已标记的函数优先极高

 

class TestBBB:

    @pytest.mark.run(order=10)
    def test_demo1(self):
        assert 2 == 2
        assert 2 == 2
        assert 2 == 2
        assert 2 == 2

    @pytest.mark.run(order=1)
    def test_demo2(self):
        assert 23 == 23
        assert 23 == 23

  

可以看到执行的顺序是按照value的值,从1到大

pytest 插件之pytest-ordering

 

相关文章:

  • 2022-12-23
  • 2021-08-29
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2021-12-25
  • 2021-11-28
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案