pytest钩子函数--pytest_collection_modifyitems执行顺序

1、在项目根目录添加config.py

def pytest_collection_modifyitems(session,items):
    print("收集的测试用例:%s"%items)
    items.sort(key=lambda x:x.name,reverse=True)
    print("排序后收集的测试用例:%s"%items)

2、代码

class Testdemo2(object):
    @pytest.mark.parametrize("data", [("zhangsan")])
    @pytest.mark.usefixtures("fix_a")
    def test_01(self,data):
        print(data)

    @pytest.mark.parametrize("data", [("lisi")])
    def test_02(self,data):
        print(data)

if __name__ == '__main__':
    pytest.main(["-v", "test_case_01.py::Testdemo2"])

 

posted @ 2021-11-19 09:25  呆呆蒙蒙  阅读(244)  评论(0编辑  收藏  举报