TestClient

noun

say it: “TEST KLY-ent” /tɛst ˈklaɪənt/

FastAPI's tool for tests that sends requests straight to your app and gives back the responses, with no server running.

What is TestClient?

TestClient sends requests to your app in tests without running a server.

client = TestClient(app)

def test_home():
    response = client.get('/')
    assert response.status_code == 200

In a sentence

  • “With a TestClient, the whole test suite runs without starting Uvicorn.”
  • “The test uses a TestClient to send GET /recipes/1 and checks the status is 200.”

Level: Journeyman · More FastAPI terms at this level

Updated