我正在创建一个函数,它在一些测试之后执行,生成一个输出文件。我想检查进程在内存中的输出是否与之前的测试运行存在差异,如果有任何差异,则显示测试日志中的差异和测试失败。
with open(os.path.join(path, f"{test_name}.json"), "r") as local_file:
local_data = json.loads(local_file.read())
differences = jsondiff.diff(local_data, payload["args"][1])
if differences:
print(differences)
raise ValueError("There are some differences with {test_name}.json file")这将在测试日志中显示以下输出。

但我不想展示这个,我想展示不同之处和test_name。
我是否需要在此方法中添加断言或创建客户异常?
发布于 2020-02-08 05:56:48
你希望你的字符串是一个f-string
with open(os.path.join(path, f"{test_name}.json"), "r") as local_file:
local_data = json.loads(local_file.read())
differences = jsondiff.diff(local_data, payload["args"][1])
if differences:
print(differences)
raise ValueError(f"There are some differences with {test_name}.json file")
#This ^
#Is what you were missinghttps://stackoverflow.com/questions/60121596
复制相似问题