import pytest class TestCalc: @pytest.mark.ces # 这个是指定你想要让这条case在那个环境下运行,后边的这个ces可以随便写 @pytest.mark.run(order=30) # 这个是处理用例执行的优先级的,数字越小。优先级越高,但是要想让这个优先级生效的话,必须得通过pip来安装pytest_ordering这个包 def test_cacl1(self): print('-----token') @pytest.mark.yufa @pytest.mark.ces # 也可以这样写,这样就证明,这条case既可以在测试环境运行,也能在预发环境下运行 @pytest.mark.run(order=1) def test_cacl2(self): print("----所有用例执行之前都执行这个") @pytest.mark.shengchan @pytest.mark.run(order=20) def test_cacl3(self): print('----sdgfdg') if __name__ == '__main__' pytest.main()#这样运行的是当前目录下所有的文件夹里边的test开头的用例和Test开头的类 pytest.main(['-s', __file__]) # 加一个-s就给print里边的内容打印出来了,-s是打印详细的信息 # pytest.main(['-m', 'ces', __file__]) #-m是指定,你想要运行哪条case的,指定ces就是至运行上边打的标签为ces的用例 # pytest.main(['-m','ces and shengchan' ,__file__])#这个是可以同时运行两个标签下的用例
python使用pytest框架设置用例在那个环境下执行,和用例执行的优先级
最新推荐文章于 2024-06-03 13:31:43 发布