4、pytest执行测试用例的顺序

340 阅读1分钟

知识库:

unittest是使用ascll的大小来绝对的执行顺序

pytest-ordering属于pytest的一个插件,它可以控制pytest的执行顺序。

pytest测试用例执行顺序默认从上到下

改变默认的执行顺序,使用mark标记

@pytest.mark.run(order=1) test_first代码如下所示

#coding=utf-8
import time
import pytest

class Test_Pytest():
        @pytest.mark.run(order=3)
        def test_one(self,):
                print("test_one方法执行" )

        @pytest.mark.run(order=2)
        def test_two(self):
                print("test_two方法执行" )

        @pytest.mark.run(order=1)
        def test_three(self):
                print("test_three方法执行" )

        def test_four(self):
                print("test_four方法执行")

我们执行下,看下结果如何 可以明显看到先有顺序执行使用mark标记的用例,再去执行未标记顺序的用例

image.png