Coverage for tests / test_generic_parameterless_depends.py: 100%
29 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 typing import Annotated, TypeVar 1abcd
3from fastapi import Depends, FastAPI 1abcd
4from fastapi.testclient import TestClient 1abcd
5from inline_snapshot import snapshot 1abcd
7app = FastAPI() 1abcd
9T = TypeVar("T") 1abcd
11Dep = Annotated[T, Depends()] 1abcd
14class A: 1abcd
15 pass 1abcd
18class B: 1abcd
19 pass 1abcd
22@app.get("/a") 1abcd
23async def a(dep: Dep[A]): 1abcd
24 return {"cls": dep.__class__.__name__} 1efg
27@app.get("/b") 1abcd
28async def b(dep: Dep[B]): 1abcd
29 return {"cls": dep.__class__.__name__} 1efg
32client = TestClient(app) 1abcd
35def test_generic_parameterless_depends(): 1abcd
36 response = client.get("/a") 1efg
37 assert response.status_code == 200, response.text 1efg
38 assert response.json() == {"cls": "A"} 1efg
40 response = client.get("/b") 1efg
41 assert response.status_code == 200, response.text 1efg
42 assert response.json() == {"cls": "B"} 1efg
45def test_openapi_schema(): 1abcd
46 response = client.get("/openapi.json") 1hij
47 assert response.status_code == 200, response.text 1hij
48 assert response.json() == snapshot( 1hij
49 {
50 "info": {"title": "FastAPI", "version": "0.1.0"},
51 "openapi": "3.1.0",
52 "paths": {
53 "/a": {
54 "get": {
55 "operationId": "a_a_get",
56 "responses": {
57 "200": {
58 "content": {"application/json": {"schema": {}}},
59 "description": "Successful Response",
60 }
61 },
62 "summary": "A",
63 }
64 },
65 "/b": {
66 "get": {
67 "operationId": "b_b_get",
68 "responses": {
69 "200": {
70 "content": {"application/json": {"schema": {}}},
71 "description": "Successful Response",
72 }
73 },
74 "summary": "B",
75 }
76 },
77 },
78 }
79 )