diff --git a/tests/test_static.py b/tests/test_static.py index 9607c2ba4..53a969834 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -14,14 +14,6 @@ import falcon.testing as testing -@pytest.fixture() -def client(asgi): - app = _util.create_app(asgi=asgi) - client = testing.TestClient(app) - client.asgi = asgi - return client - - def normalize_path(path): # NOTE(vytas): On CPython 3.13, ntpath.isabs() no longer returns True for # Unix-like absolute paths that start with a single \. @@ -35,6 +27,22 @@ def normalize_path(path): return path +@pytest.fixture() +def client(asgi, monkeypatch): + def add_static_route_normalized(obj, prefix, directory, **kwargs): + add_static_route_orig(obj, prefix, normalize_path(directory), **kwargs) + + app = _util.create_app(asgi=asgi) + + app_cls = type(app) + add_static_route_orig = app_cls.add_static_route + monkeypatch.setattr(app_cls, 'add_static_route', add_static_route_normalized) + + client = testing.TestClient(app) + client.asgi = asgi + return client + + def create_sr(asgi, prefix, directory, **kwargs): sr_type = StaticRouteAsync if asgi else StaticRoute return sr_type(prefix, normalize_path(directory), **kwargs)