在common层获取ymal数据
#读取ymal文件
def read_yaml(self,yaml_file):
with open(yaml_file,encoding="utf-8") as f:
#文件流加载方式
value=yaml.load(f,Loader=yaml.FullLoader)
return value
使用pytest写测试用例:
@pytest.mark.parametrize(args,value)使用此注释获取yaml数据
import pytest
from common.getdata import GetData
from common.method import Method
class TestVedio:
m = Method()
@pytest.mark.parametrize("args",GetData().read_yaml("../../data/api_list/dapi_list.yaml"))
def test_camera_list(self,args):
'''
@pytest.mark.parametrize(args,value):写1个yaml读取流,用values获取到yaml数据
:param args:
:return:
'''
header = args["header"]
list_yaml=args["camera_info"]["camera_list"]
url=list_yaml["url"]
data=list_yaml["data"]
res=self.m.run_method('get',url,header,data)
print(res)
assert res['code']=='0'
if __name__ == '__main__':
pytest.main(['-vs','test_camera.py'])