14th December 2021
Computer Science⚑
Programming⚑
FastAPI⚑
-
New: Testing startup and shutdown events.
When you need your event handlers (
startup
andshutdown
) to run in your tests, you can use theTestClient
with a with statement:import pytest from fastapi.testclient import TestClient from api.main import api @pytest.fixture def client(): with TestClient(api) as client: yield client def test_endpoint(client): response = client.get("/endpoint") assert response.status_code == 200