docs_src/app_testing/tutorial001_py310.py
raw| 1 | from fastapi import FastAPI |
| 2 | from fastapi.testclient import TestClient |
| 3 | |
| 4 | app = FastAPI() |
| 5 | |
| 6 | |
| 7 | @app.get("/") |
| 8 | async def read_main(): |
| 9 | return {"msg": "Hello World"} |
| 10 | |
| 11 | |
| 12 | client = TestClient(app) |
| 13 | |
| 14 | |
| 15 | def test_read_main(): |
| 16 | response = client.get("/") |
| 17 | assert response.status_code == 200 |
| 18 | assert response.json() == {"msg": "Hello World"} |