Coverage for tests / test_include_route.py: 100%

14 statements  

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

1from fastapi import APIRouter, FastAPI, Request 1abcd

2from fastapi.responses import JSONResponse 1abcd

3from fastapi.testclient import TestClient 1abcd

4 

5app = FastAPI() 1abcd

6router = APIRouter() 1abcd

7 

8 

9@router.route("/items/") 1abcd

10def read_items(request: Request): 1abcd

11 return JSONResponse({"hello": "world"}) 1efg

12 

13 

14app.include_router(router) 1abcd

15 

16client = TestClient(app) 1abcd

17 

18 

19def test_sub_router(): 1abcd

20 response = client.get("/items/") 1efg

21 assert response.status_code == 200, response.text 1efg

22 assert response.json() == {"hello": "world"} 1efg