Coverage for tests / test_stringified_annotation_dependency.py: 100%
32 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from __future__ import annotations 1abdc
3from typing import TYPE_CHECKING, Annotated 1abdc
5import pytest 1abdc
6from fastapi import Depends, FastAPI 1abdc
7from fastapi.testclient import TestClient 1abdc
8from inline_snapshot import snapshot 1abdc
10if TYPE_CHECKING: # pragma: no cover 1abdc
11 from collections.abc import AsyncGenerator
14class DummyClient: 1abdc
15 async def get_people(self) -> list: 1abdc
16 return ["John Doe", "Jane Doe"] 1efg
18 async def close(self) -> None: 1abdc
19 pass 1efg
22async def get_client() -> AsyncGenerator[DummyClient, None]: 1abdc
23 client = DummyClient() 1efg
24 yield client 1efg
25 await client.close() 1efg
28Client = Annotated[DummyClient, Depends(get_client)] 1abdc
31@pytest.fixture(name="client") 1abdc
32def client_fixture() -> TestClient: 1abdc
33 app = FastAPI() 1abc
35 @app.get("/") 1abc
36 async def get_people(client: Client) -> list: 1abc
37 return await client.get_people() 1efg
39 client = TestClient(app) 1abc
40 return client 1abc
43def test_get(client: TestClient): 1abdc
44 response = client.get("/") 1efg
45 assert response.status_code == 200, response.text 1efg
46 assert response.json() == ["John Doe", "Jane Doe"] 1efg
49def test_openapi_schema(client: TestClient): 1abdc
50 response = client.get("/openapi.json") 1hij
51 assert response.status_code == 200, response.text 1hij
52 assert response.json() == snapshot( 1hij
53 {
54 "openapi": "3.1.0",
55 "info": {"title": "FastAPI", "version": "0.1.0"},
56 "paths": {
57 "/": {
58 "get": {
59 "summary": "Get People",
60 "operationId": "get_people__get",
61 "responses": {
62 "200": {
63 "description": "Successful Response",
64 "content": {
65 "application/json": {
66 "schema": {
67 "items": {},
68 "type": "array",
69 "title": "Response Get People Get",
70 }
71 }
72 },
73 }
74 },
75 }
76 }
77 },
78 }
79 )