Coverage for tests / test_empty_router.py: 100%
22 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import pytest 1abcd
2from fastapi import APIRouter, FastAPI 1abcd
3from fastapi.exceptions import FastAPIError 1abcd
4from fastapi.testclient import TestClient 1abcd
6app = FastAPI() 1abcd
8router = APIRouter() 1abcd
11@router.get("") 1abcd
12def get_empty(): 1abcd
13 return ["OK"] 1efg
16app.include_router(router, prefix="/prefix") 1abcd
19client = TestClient(app) 1abcd
22def test_use_empty(): 1abcd
23 with client: 1efg
24 response = client.get("/prefix") 1efg
25 assert response.status_code == 200, response.text 1efg
26 assert response.json() == ["OK"] 1efg
28 response = client.get("/prefix/") 1efg
29 assert response.status_code == 200, response.text 1efg
30 assert response.json() == ["OK"] 1efg
33def test_include_empty(): 1abcd
34 # if both include and router.path are empty - it should raise exception
35 with pytest.raises(FastAPIError): 1hij
36 app.include_router(router) 1hij