fastapi/tests/test_dependency_pep695_py31...

30 lines
616 B
Python

from __future__ import annotations
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from .utils import needs_py312
async def some_value() -> int:
return 123
type DependedValue = Annotated[int, Depends(some_value)]
@needs_py312
def test_pep695_type_dependencies():
app = FastAPI()
@app.get("/")
async def get_with_dep(value: DependedValue) -> str: # noqa
return f"value: {value}"
client = TestClient(app)
response = client.get("/")
assert response.status_code == 200
assert response.text == '"value: 123"'