Coverage for tests / test_tutorial / test_custom_response / test_tutorial001.py: 100%
17 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
1import importlib 1abdc
3import pytest 1abdc
4from fastapi.testclient import TestClient 1abdc
5from inline_snapshot import snapshot 1abdc
8@pytest.fixture( 1abdc
9 name="client",
10 params=[
11 pytest.param("tutorial001_py310"),
12 pytest.param("tutorial010_py310"),
13 ],
14)
15def get_client(request: pytest.FixtureRequest): 1abdc
16 mod = importlib.import_module(f"docs_src.custom_response.{request.param}") 1abc
17 client = TestClient(mod.app) 1abc
18 return client 1abc
21def test_get_custom_response(client: TestClient): 1abdc
22 response = client.get("/items/") 1efg
23 assert response.status_code == 200, response.text 1efg
24 assert response.json() == [{"item_id": "Foo"}] 1efg
27def test_openapi_schema(client: TestClient): 1abdc
28 response = client.get("/openapi.json") 1hij
29 assert response.status_code == 200, response.text 1hij
30 assert response.json() == snapshot( 1hij
31 {
32 "openapi": "3.1.0",
33 "info": {"title": "FastAPI", "version": "0.1.0"},
34 "paths": {
35 "/items/": {
36 "get": {
37 "responses": {
38 "200": {
39 "description": "Successful Response",
40 "content": {"application/json": {"schema": {}}},
41 }
42 },
43 "summary": "Read Items",
44 "operationId": "read_items_items__get",
45 }
46 }
47 },
48 }
49 )