Coverage for tests / test_tutorial / test_custom_request_and_route / test_tutorial002.py: 100%
16 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 dirty_equals import IsOneOf 1abdc
5from fastapi.testclient import TestClient 1abdc
7from tests.utils import needs_py310 1abdc
10@pytest.fixture( 1abdc
11 name="client",
12 params=[
13 pytest.param("tutorial002_py310", marks=needs_py310),
14 pytest.param("tutorial002_an_py310", marks=needs_py310),
15 ],
16)
17def get_client(request: pytest.FixtureRequest): 1abdc
18 mod = importlib.import_module(f"docs_src.custom_request_and_route.{request.param}") 1abc
20 client = TestClient(mod.app) 1abc
21 return client 1abc
24def test_endpoint_works(client: TestClient): 1abdc
25 response = client.post("/", json=[1, 2, 3]) 1efg
26 assert response.json() == 6 1efg
29def test_exception_handler_body_access(client: TestClient): 1abdc
30 response = client.post("/", json={"numbers": [1, 2, 3]}) 1hij
31 assert response.json() == { 1hij
32 "detail": {
33 "errors": [
34 {
35 "type": "list_type",
36 "loc": ["body"],
37 "msg": "Input should be a valid list",
38 "input": {"numbers": [1, 2, 3]},
39 }
40 ],
41 # httpx 0.28.0 switches to compact JSON https://github.com/encode/httpx/issues/3363
42 "body": IsOneOf('{"numbers": [1, 2, 3]}', '{"numbers":[1,2,3]}'),
43 }
44 }