Skip to content

Testing

pyqwest.testing.ASGITransport

Bases: Transport

Transport implementation that directly invokes an ASGI application. Useful for testing.

The ASGI transport supports lifespan - to use it, make sure to use the transport as an asynchronous context manager. Lifespan startup will be run on entering and shutdown when exiting.

Parameters:

Name Type Description Default
app ASGIApplication

The ASGI application to invoke.

required
http_version HTTPVersion

The HTTP version to mimic for requests. Note, semantics such as lack of bidirectional streaming for HTTP/1 are not enforced.

HTTP2
client tuple[str, int]

The (host, port) tuple to use for the client address in the ASGI scope.

('127.0.0.1', 111)

app_exception property

The exception raised by the ASGI application, if any.

This will be overwritten for any request which raises an exception, so it is generally expected to be used with a transport that is used only once, or in a precise order.

pyqwest.testing.WSGITransport

Bases: SyncTransport

Transport implementation that directly invokes a WSGI application. Useful for testing.

Parameters:

Name Type Description Default
app WSGIApplication

The WSGI application to invoke for requests.

required
http_version HTTPVersion

The HTTP version to simulate for requests.

HTTP2
executor ThreadPoolExecutor | None

An optional ThreadPoolExecutor to use for running the WSGI app. If not provided, a default executor will be used.

None

app_exception property

The exception raised by the ASGI application, if any.

This will be overwritten for any request which raises an exception, so it is generally expected to be used with a transport that is used only once, or in a precise order.

error_stream property

The error stream to which the WSGI application writes.

This is not reset per request or threadsafe, so it is generally expected to be used with a transport that is used only once, or in a precise order.