MCPcopy
hub / github.com/fastapi/fastapi / test_read_items

Function test_read_items

docs_src/app_testing/tutorial004_py310.py:26–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24
25
26def test_read_items():
27 # Before the lifespan starts, "items" is still empty
28 assert items == {}
29
30 with TestClient(app) as client:
31 # Inside the "with TestClient" block, the lifespan starts and items added
32 assert items == {"foo": {"name": "Fighters"}, "bar": {"name": "Tenders"}}
33
34 response = client.get("/items/foo")
35 assert response.status_code == 200
36 assert response.json() == {"name": "Fighters"}
37
38 # After the requests is done, the items are still there
39 assert items == {"foo": {"name": "Fighters"}, "bar": {"name": "Tenders"}}
40
41 # The end of the "with TestClient" block simulates terminating the app, so
42 # the lifespan ends and items are cleaned up
43 assert items == {}

Callers 1

test_mainFunction · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…