import yaml
import os
path = os.path.join(os.path.dirname(os.path.dirname(__file__)))
def open_yaml(flag, file='three_api.yaml'):
# 读取yaml
try:
with open(path + "/hy_file/" + file, 'rb') as f:
temp = yaml.load(f.read())
return temp[flag]
except Exception as e:
log.info('读取失败' + file, e)
def set_yaml(key, value, filepath='three_api.yaml'):
# 先读取后写入
try:
with open(path + "/hy_file/" + filepath, 'r', encoding='gbk') as f:
result = f.read()
doc = yaml.load(result, Loader=yaml.FullLoader)
# 修改的值
doc['TestCase'][key]['varargus'] = value
with open(path + "/hy_file/" + filepath, 'w', encoding='utf-8') as w_f:
# 写入
yaml.dump(doc, w_f)
except Exception as e:
log.info('写入文件失败' + filepath, e)
yaml 读取写入封装
最新推荐文章于 2024-03-14 18:10:21 发布