【发布时间】:2018-12-07 14:37:15
【问题描述】:
我正在使用 Tavern 工具进行 API 测试,我想在执行测试时将返回的响应保存在 JSON 文件中,因此我使用以下代码来响应 yaml 测试文件:
response:
status_code: 200
save:
$ext:
function: tavern_utils:save_response
tavern_utils:save_response() 函数:
def save_response(response):
with open('saved.json','w') as file:
json.dump(file,response.json())
所以在使用 pytest 执行测试时,出现以下错误:
TypeError: The Object of type 'TextIOWrapper' is not JSON serializable
如何解决此错误或通过任何其他方法保存响应?
【问题讨论】:
标签: python json rest dictionary pytest