One of the design principles of Bocadillo is to make it easy to write high-quality applications. This includes helping you write great tests and ensure the quality of your apps.
We wrote specific how-to guides on integrating Bocadillo with the following test frameworks:
from bocadillo import App, create_client app = App() client = create_client(app)
TestClient exposes the same interface as the requests library, and has other useful features such as WebSocket testing helpers.
We recommend you read the documentation for Starlette's test client for further information.
If you need to perform integration tests against a live server, the
LiveServer context manager should come handy. It starts a uvicorn server in a separate process, and terminates it when exiting the context. You can then make requests to it, e.g. using requests:
import requests from bocadillo import App, configure, LiveServer app = App() configure(app) with LiveServer(app) as server: response = requests.get(server.url("/foo"))
Overriding environment variables
If you need to override some environment variables during your tests, you may find the
override_env helper useful:
from bocadillo.utils import override_env with override_env("APP_ENV", "testing"): ...