Coverage for tests / test_tutorial / test_events / test_tutorial002.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import pytest 1abcd
2from fastapi import FastAPI 1abcd
3from fastapi.testclient import TestClient 1abcd
4from inline_snapshot import snapshot 1abcd
6from tests.utils import workdir_lock 1abcd
9@pytest.fixture(name="app", scope="module") 1abcd
10def get_app(): 1abcd
11 with pytest.warns(DeprecationWarning): 1mnop
12 from docs_src.events.tutorial002_py310 import app 1mnop
13 yield app 1mnop
16@workdir_lock 1abcd
17def test_events(app: FastAPI): 1abcd
18 with TestClient(app) as client: 1efgh
19 response = client.get("/items/") 1efgh
20 assert response.status_code == 200, response.text 1efgh
21 assert response.json() == [{"name": "Foo"}] 1efgh
22 with open("log.txt") as log: 1efgh
23 assert "Application shutdown" in log.read() 1efgh
26@workdir_lock 1abcd
27def test_openapi_schema(app: FastAPI): 1abcd
28 with TestClient(app) as client: 1ijkl
29 response = client.get("/openapi.json") 1ijkl
30 assert response.status_code == 200, response.text 1ijkl
31 assert response.json() == snapshot( 1ijkl
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 )