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