Coverage for docs_src / app_testing / tutorial003_py310.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from fastapi import FastAPI 1abc

2from fastapi.testclient import TestClient 1abc

3 

4app = FastAPI() 1abc

5 

6items = {} 1abc

7 

8 

9@app.on_event("startup") 1abc

10async def startup_event(): 1abc

11 items["foo"] = {"name": "Fighters"} 1abc

12 items["bar"] = {"name": "Tenders"} 1abc

13 

14 

15@app.get("/items/{item_id}") 1abc

16async def read_items(item_id: str): 1abc

17 return items[item_id] 1abc

18 

19 

20def test_read_items(): 1abc

21 with TestClient(app) as client: 1abc

22 response = client.get("/items/foo") 1abc

23 assert response.status_code == 200 1abc

24 assert response.json() == {"name": "Fighters"} 1abc