-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Description
Describe the bug
Without fastapi-versioning, dependency_overrides can easily be specified on the app contained in the TestClient a la (pytest fixture like pseudo code):
before = client.app.dependency_overrides
client.app.dependency_overrides = dict(overrides)
try:
yield
finally:
client.app.dependency_overrides = beforeWith the internal use of sub application mounts, this doesn't work anymore and the override never reaches one of the versioned sub applications.
To Reproduce
Steps to reproduce the behavior:
from fastapi import APIRouter, Depends, FastAPI
from fastapi.testclient import TestClient
from fastapi_versioning import versioned_api_route, VersionedFastAPI
app = FastAPI(title="test-app")
router = APIRouter(route_class=versioned_api_route(1, 0))
def dependency() -> str:
return "original"
@router.get("/test")
def get_test(dep: str = Depends(dependency)) -> str:
return dep
app.include_router(router)
app = VersionedFastAPI(app)
def test_this() -> None:
client = TestClient(app)
client.app.dependency_overrides = {dependency: lambda: "patched"}
assert client.get("/v1_0/test").json() == "patched"This test will fail
Expected behavior
It should at least be documented how to access the correct sub application for providing the dependency_overrides.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels