pytest -ordering 更改执行用例的顺序

示例代码

import pytest

class Test_login():
    def test_login_001(self):
        print("\n test login 001")

    def test_login_002(self):
        print("\n test login 002")

    def test_login_003(self):
        print("\n test login 003")

    def test_login_004(self):
        print("\n test login 004") 

运行结果:

 

修改上面的示例:在每个function前增加一句  @pytest.mark.run(order=x)

import pytest

class Test_login():
    @pytest.mark.run(order=3)
    def test_login_001(self):
        print("\n test login 001")

    @pytest.mark.run(order=4)
    def test_login_002(self):
        print("\n test login 002")

    @pytest.mark.run(order=1)
    def test_login_003(self):
        print("\n test login 003")

    @pytest.mark.run(order=2)
    def test_login_004(self):
        print("\n test login 004") 

运行结果:

可以看到用例的执行顺序完全是按照order的顺序来运行的!



相关文章

目录1、前言2、mark的使用(一)注册自定义标记(二)在测试...
用例执行状态用例执行完成后,每条用例都有自己的状态,常见...
什么是conftest.py可以理解成一个专门存放fixture的配置文件...
前言pytest默认执行用例是根据项目下的文件名称按ascii码去收...
前言:什么是元数据?元数据是关于数据的描述,存储着关于数...