From b1ec7a1479814c56b646e5e6e8770b15df7325cf Mon Sep 17 00:00:00 2001 From: Felipe Carvajal Date: Mon, 23 Feb 2026 23:33:30 -0300 Subject: [PATCH] packaged test into function fix --- tests/test_router_mount.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tests/test_router_mount.py b/tests/test_router_mount.py index 0a36544c9..9bee074f4 100644 --- a/tests/test_router_mount.py +++ b/tests/test_router_mount.py @@ -1,20 +1,25 @@ from fastapi import FastAPI, APIRouter from fastapi.testclient import TestClient -app = FastAPI() -api_router = APIRouter(prefix="/api") -@api_router.get("/app") -def read_main(): - return {"message": "Hello World from main app"} +def test_mount_on_router(): + app = FastAPI() + api_router = APIRouter(prefix="/api") -subapi = FastAPI() + @api_router.get("/app") + def read_main(): + return {"message": "Hello World from main app"} -@subapi.get("/sub") -def read_sub(): - return {"message": "Hello World from sub API"} + subapi = FastAPI() -api_router.mount("/subapi", subapi) # ← moved up -app.include_router(api_router) # ← now after + @subapi.get("/sub") + def read_sub(): + return {"message": "Hello World from sub API"} -print("All tests passed.") \ No newline at end of file + api_router.mount("/subapi", subapi) + app.include_router(api_router) + + client = TestClient(app) + + assert client.get("/api/app").status_code == 200 + assert client.get("/api/subapi/sub").status_code == 200 \ No newline at end of file