generate a blank response object for testing generate a blank response object for testing flask flask

generate a blank response object for testing


I'm not sure I fully understand, but what's wrong with

from flask import Responseresponse = Response()

?

Flask documentation - Response object


If you're referring to generating an instance of an object inline, you can use this syntax

response = type('obj', (object,), {'status_code' : None, 'text' : None})

Update User added flask reference after this answer, leaving for reference


What about subclassing a class you want to fake?

import flaskclass FakeResponse(flask.Response):    def __init__(self, response=None, status=None, headers=None, mimetype=None, content_type=None, direct_passthrough=False):        self.headers = {}        self.status_code = 200        self.text = ""

As an advantage, FakeResponse interface would strictly conform original Response object (it'll include all properties and methods of original one).