Coverage for docs_src / app_testing / tutorial003_py310.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1from fastapi import FastAPI 1abcd
2from fastapi.testclient import TestClient 1abcd
4app = FastAPI() 1abcd
6items = {} 1abcd
9@app.on_event("startup") 1abcd
10async def startup_event(): 1abcd
11 items["foo"] = {"name": "Fighters"} 1abcd
12 items["bar"] = {"name": "Tenders"} 1abcd
15@app.get("/items/{item_id}") 1abcd
16async def read_items(item_id: str): 1abcd
17 return items[item_id] 1abcd
20def test_read_items(): 1abcd
21 with TestClient(app) as client: 1abcd
22 response = client.get("/items/foo") 1abcd
23 assert response.status_code == 200 1abcd
24 assert response.json() == {"name": "Fighters"} 1abcd