Coverage for tests / test_tutorial / test_custom_response / test_tutorial001.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1import importlib 1abcd

2 

3import pytest 1abcd

4from fastapi.testclient import TestClient 1abcd

5from inline_snapshot import snapshot 1abcd

6 

7 

8@pytest.fixture( 1abcd

9 name="client", 

10 params=[ 

11 pytest.param("tutorial001_py310"), 

12 ], 

13) 

14def get_client(request: pytest.FixtureRequest): 1abcd

15 mod = importlib.import_module(f"docs_src.custom_response.{request.param}") 1efghijkl

16 client = TestClient(mod.app) 1efghijkl

17 return client 1efghijkl

18 

19 

20@pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning") 1abcd

21def test_get_custom_response(client: TestClient): 1abcd

22 response = client.get("/items/") 1mnop

23 assert response.status_code == 200, response.text 1mnop

24 assert response.json() == [{"item_id": "Foo"}] 1mnop

25 

26 

27@pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning") 1abcd

28def test_openapi_schema(client: TestClient): 1abcd

29 response = client.get("/openapi.json") 1qrst

30 assert response.status_code == 200, response.text 1qrst

31 assert response.json() == snapshot( 1qrst

32 { 

33 "openapi": "3.1.0", 

34 "info": {"title": "FastAPI", "version": "0.1.0"}, 

35 "paths": { 

36 "/items/": { 

37 "get": { 

38 "responses": { 

39 "200": { 

40 "description": "Successful Response", 

41 "content": {"application/json": {"schema": {}}}, 

42 } 

43 }, 

44 "summary": "Read Items", 

45 "operationId": "read_items_items__get", 

46 } 

47 } 

48 }, 

49 } 

50 )