'Wraps a WSGI application in a more convenient interface for
testing.
``app`` may be an application, or a Paste Deploy app
URI, like ``\'config:filename.ini#test\'``.
``namespace`` is a dictionary that will be written to (if
provided).  This can be used with doctest or some other
system, and the variable ``res`` will be assigned everytime
you make a request (instead of returning the request).
``relative_to`` is a directory, and filenames used for file
uploads are calculated relative to this.  Also ``config:``
URIs that aren\'t absolute.
``extra_environ`` is a dictionary of values that should go
into the environment for each request.  These can provide a
communication channel with the application.
``pre_request_hook`` is a function to be called prior to
making requests (such as ``post`` or ``get``). This function
must take one argument (the instance of the TestApp).
``post_request_hook`` is a function, similar to
``pre_request_hook``, to be called after requests are made.'

def __init__(self, app, namespace=None, relative_to=None, extra_environ=None, pre_request_hook=None, post_request_hook=None):

    if isinstance(app, (six.binary_type, six.text_type)):
        from paste.deploy import loadapp
        app = loadapp(app, relative_to=relative_to)
    self.app = app
    self.namespace = namespace
    self.relative_to = relative_to
    if (extra_environ is None):
        extra_environ = {}
    self.extra_environ = extra_environ
    self.pre_request_hook = pre_request_hook
    self.post_request_hook = post_request_hook
    self.reset()
