Move ForwardRef annotated dependency test to dedicated module

This commit is contained in:
Amulya K H 2026-02-04 07:43:46 +05:30
parent 49daf31abd
commit dc0029f114
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
from typing import Annotated, ForwardRef
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
def test_annotated_forwardref_dependency():
app = FastAPI()
User = ForwardRef("User")
def get_user() -> "User":
return {"name": "amulya"}
@app.get("/")
def read_user(user: Annotated[User, Depends(get_user)]):
return user
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"name": "amulya"}