I am using Tavern tool for API testing and I want to save the returned response in a JSON file while the test is being executed so I am using the following code in response of the yaml test file:
response:
status_code: 200
save:
$ext:
function: tavern_utils:save_response
The tavern_utils:save_response() function:
def save_response(response):
with open('saved.json','w') as file:
json.dump(file,response.json())
So while executing the test with pytest, I get the following error:
TypeError: The Object of type 'TextIOWrapper' is not JSON serializable
How to solve this error or save the response by any other method?