string.Template模板中参数要传空时,处理
1、yaml文件
headers: null
json:
name: $name
parentid: $parentid
method: post
params:
access_token: $access_token
url: https://$host/cgi-bin/department/create
2、替换yaml文件模板内容
def get_api_yaml_data(filename, template: dict):
env_config = DoYamlFile.get_env_config()
template["host"] = env_config["test_env"][env_config["default"]]
print(template)
with open(os.path.join(api_yaml_path, filename), encoding="utf-8") as f:
# 先用template替换模板内容
res1 = Template(f.read()).substitute(template)
# 用yaml格式化成dict
res = yaml.safe_load(res1)
3. 需要将 $name传""给接口时
调用 get_api_yaml_data方法时,template参数中,要将name设置为:{"name":"null"}