pytest测试框架2【控制用例的执行顺序】

1.pytest加载所有的测试用例都是乱序的,如果想指定用例的顺序,可以使用pytest-ordering插件,指定用例的执行顺序只需要在测试用例的方法前面加上装饰器@pytest.mark.run(order=[num])设置order的对应的num值,它就可以按照num的大小顺序来执行

应用场景:有时运行测试用例需要指定它的顺序,比如有些场景需要先登录,才能执行后续的流程比如购物流程,下单流程,这时需要指定用例的顺序,
安装:pip install pytest-ordering

import pytest


class TestPytest(object):
    @pytest.mark.run(order=-1)
    def test_two(self):
        print("\ntest_two,测试用例")

    @pytest.mark.run(order=3)
    def test_one(self):
        print("\ntest_one,测试用例")

    @pytest.mark.run(order=1)
    def test_three(self):
        print("\ntest_three,测试用例")

posted @ 2022-09-18 22:05  当时只道是寻常呀  阅读(171)  评论(0)    收藏  举报