You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
617 B

from __future__ import annotations
from dataclasses import dataclass
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
def test_annotated_forwardref_dependency():
app = FastAPI()
def get_item() -> Item:
return Item(name="apple")
@app.get("/")
def read(item: Annotated[Item, Depends(get_item)]):
return {"name": item.name}
@dataclass
class Item:
name: str
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"name": "apple"}