Warning: Bocadillo is now UNMAINTAINED. Users are recommended to migrate to a supported alternative, such as Starlette or FastAPI. Please see #344 for more information.

bocadillo.testing

create_client

create_client(app:'App', **kwargs) -> starlette.testclient.TestClient

Create a Starlette Test Client out of an application.

Parameters

  • app: an #::bocadillo.applications#App instance.
  • **kwargs (any): keyword arguments passed to the TestClient constructor.

Returns

client (TestClient): a Starlette test client.

LiveServer

LiveServer(self, app:'App', ready_timeout:float=5, stop_timeout:float=5, **kwargs)

Context manager to spin up a live uvicorn server in a separate process.

The server process is terminated when exiting the context.

Parameters

  • app: an #::bocadillo.applications#App instance.
  • ready_timeout (float): The maximum time to wait for the live server to be ready to handle connections, in seconds. Defaults to 5.
  • stop_timeout (float): The maximum time to wait for the live server to terminate, in seconds. Defaults to 5.
  • **kwargs (any): keyword arguments passed to uvicorn.run(). host defaults to "127.0.0.1." (i.e. localhost). port defaults to a random integer between 3000 and 9999.

Attributes

  • url (str): the full URL where the server lives. Build a full URL by calling this attribute, e.g. server.url("/path/foo").