在做Yaml case文件拼接时遇到一个问题,就是把中文字符load出来再dump到yaml文件时,中文字符都显示为16进制编码而不是显示中文,查了下pyyaml官网资料,终于找到解决办法, dump 时加入3个参数:



def generate_yaml(suite):
file_name = suite + ".yaml"
with open(file_name, "r") as yaml_file:
yaml_obj = yaml.load(yaml_file.read(),Loader=yaml.FullLoader)

with open("./android.yaml", "a") as yaml_file:
yaml.dump(yaml_obj, yaml_file,default_flow_style=False,encoding='utf-8',allow_unicode=True)