mirror of https://gitee.com/a529548204/apitest.git
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# coding:utf-8
|
|
import logging
|
|
import os
|
|
|
|
import yaml
|
|
|
|
from config.confManage import dir_manage
|
|
from util.scripts import root_path
|
|
from util.tools.getFileNames import getFilePathList
|
|
import logging
|
|
|
|
datapath = root_path + dir_manage("${test_suite}$") + dir_manage("${data_dir}$") + "/" + dir_manage("${test_name}$")
|
|
|
|
|
|
def ini_allyaml():
|
|
"""
|
|
获取全部yaml数据
|
|
:return:
|
|
"""
|
|
alldata = {}
|
|
datalist = getFilePathList(datapath,".yml")
|
|
for file in datalist:
|
|
try:
|
|
with open(file, 'r', encoding="utf-8") as f:
|
|
file_data = yaml.safe_load(f.read())
|
|
for k,v in file_data.items():
|
|
if k in alldata:
|
|
raise Exception("存在重复case")
|
|
if not file_data["headers"]:
|
|
file_data["headers"] = {}
|
|
alldata= {**alldata,**file_data}
|
|
except UnicodeDecodeError:
|
|
with open(file, 'r') as f:
|
|
file_data = yaml.safe_load(f.read())
|
|
for k,v in file_data.items():
|
|
if k in alldata:
|
|
raise Exception("存在重复case")
|
|
alldata= {**alldata,**file_data}
|
|
logging.info("*"*200)
|
|
return alldata
|
|
|
|
def ini_yaml(filename, path=datapath):
|
|
try:
|
|
with open(path + "/" + filename, 'r', encoding="utf-8") as f:
|
|
file_data = f.read()
|
|
data = yaml.safe_load(file_data)
|
|
|
|
return data
|
|
except UnicodeDecodeError:
|
|
with open(path + "/" + filename, 'r') as f:
|
|
file_data = f.read()
|
|
data = yaml.safe_load(file_data)
|
|
|
|
return data
|
|
|
|
if __name__ == '__main__':
|
|
# print(datapath)
|
|
# get_yaml_data(r"F:\api2.0\config\runConfig.yml")
|
|
d = ini_allyaml()
|
|
print(d)
|
|
# # case_level = runConfig_dict[0]["address"].format(**{"home_id": "123"})
|
|
# print(runConfig_dict)
|
|
|
|
# print(case_level)
|
|
# print(type(case_level))
|