微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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的顺序来运行的!



版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐