调用父类 yaml safe_load封装方法没有返回内容

image
为什么在testTag中读取文件,保存在data变量,输出data没有内容,导致后续的数据参数化失败,如果直接在testTag中加载文件就可以了,调用BaseApi进行返回就没有内容,大佬请赐教。

BaseApi yaml_load方法:
image

去掉yaml load函数里的print语句试试

不行,才加上print输出看结果的 :sob:

这个例子可以说明你的问题


def test_dump():
    s = {"xx": "中文"}
    with open("temp_dump.yaml", 'w', encoding="utf-8") as f:
        yaml.dump(s, f,
                  default_flow_style=False,
                  indent=2, allow_unicode=True, encoding="utf-8")

    with open("temp_dump.yaml", encoding="utf-8") as f:
        # 第一次读取的时候,是从头开始读,f的读取从开头变成了结尾
        print("first")
        print(yaml.safe_load(f))

        # 第二次再读,是从f的结尾开始,所以读不到
        print("second")
        print(yaml.safe_load(f))

        # 第三次再读,把f的读取位置挪到开头
        print("third")
        f.seek(0)
        print(yaml.safe_load(f))

输出

first
{'xx': '中文'}
second
None
third
{'xx': '中文'}
PASSED

好的 明白了 谢谢~