【Python_pytest】pytest_ordering 测试用例运行顺序


pytest测试用例执行顺序

默认是按照书写顺序执行

调整测试用例执行顺序可使用 pytest_ordering

# 安装后无需导入直接使用
pip install pytest_ordering
# coding:utf-8
import pytest

class TestAuto:

    env = "sit"
    num = 1
    

    def setup_class(self):
        print("同一测试类下在所有测试用例执行前,有且只执行一次")

    def teardown_class(self):
        print("同一测试类下在所有测试用例执行后,有且只执行一次")

    def setup(self):
        print("同一测试类下在每个测试用例执行前,均执行一次")

    def teardown(self):
        print("同一测试类下在每个测试用例执行后,均执行一次")

    @pytest.mark.run(order=1)
    def test_case_san(self):
        print("case1")

    @pytest.mark.run(order=0)
    def test_case_abc(self):
        print("case2")

if __name__ == "__main__":
    pytest.main(["-s", "test_debug.py"])

执行结果: