From 704d3adb36285215a196b0740993ff78e06e8ec9 Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Thu, 12 Feb 2026 12:45:52 +0100 Subject: [PATCH] Parameterize test to ensure it works with `root_path` --- tests/test_apirouter_mount.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_apirouter_mount.py b/tests/test_apirouter_mount.py index a873cfa49..6c0bb89a8 100644 --- a/tests/test_apirouter_mount.py +++ b/tests/test_apirouter_mount.py @@ -1,3 +1,5 @@ +from pathlib import Path + import pytest from fastapi import APIRouter, FastAPI from fastapi.exceptions import FastAPIError @@ -5,18 +7,19 @@ from fastapi.staticfiles import StaticFiles from fastapi.testclient import TestClient -def test_mount_static_files_to_apirouter(tmp_path): +@pytest.mark.parametrize("root_path", ["", "/v1"]) +def test_mount_static_files_to_apirouter(tmp_path: Path, root_path: str): static_asset = tmp_path / "index.html" static_asset.write_text("Hello, World!") router = APIRouter() router.mount("/static", StaticFiles(directory=tmp_path), name="static") - app = FastAPI() + app = FastAPI(root_path=root_path or None) app.include_router(router) client = TestClient(app) - response = client.get("/static/index.html") + response = client.get(f"{root_path}/static/index.html") assert response.status_code == 200 assert response.text == "Hello, World!"