mirror of https://github.com/tiangolo/fastapi.git
Add tests for pepe695 compatibility
This commit is contained in:
parent
07aff37a59
commit
5d7dbf8b1a
|
|
@ -0,0 +1,28 @@
|
||||||
|
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:
|
||||||
|
return f"value: {value}"
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
response = client.get("/")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.text == '"value: 123"'
|
||||||
|
|
@ -8,6 +8,9 @@ needs_py39 = pytest.mark.skipif(sys.version_info < (3, 9), reason="requires pyth
|
||||||
needs_py310 = pytest.mark.skipif(
|
needs_py310 = pytest.mark.skipif(
|
||||||
sys.version_info < (3, 10), reason="requires python3.10+"
|
sys.version_info < (3, 10), reason="requires python3.10+"
|
||||||
)
|
)
|
||||||
|
needs_py312 = pytest.mark.skipif(
|
||||||
|
sys.version_info < (3, 12), reason="requires python3.12+"
|
||||||
|
)
|
||||||
needs_pydanticv2 = pytest.mark.skipif(not PYDANTIC_V2, reason="requires Pydantic v2")
|
needs_pydanticv2 = pytest.mark.skipif(not PYDANTIC_V2, reason="requires Pydantic v2")
|
||||||
needs_pydanticv1 = pytest.mark.skipif(PYDANTIC_V2, reason="requires Pydantic v1")
|
needs_pydanticv1 = pytest.mark.skipif(PYDANTIC_V2, reason="requires Pydantic v1")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue