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