Coverage for tests / test_tutorial / test_custom_request_and_route / test_tutorial003.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import importlib 1abdc

2 

3import pytest 1abdc

4from fastapi.testclient import TestClient 1abdc

5 

6from tests.utils import needs_py310 1abdc

7 

8 

9@pytest.fixture( 1abdc

10 name="client", 

11 params=[ 

12 pytest.param("tutorial003_py310", marks=needs_py310), 

13 ], 

14) 

15def get_client(request: pytest.FixtureRequest): 1abdc

16 mod = importlib.import_module(f"docs_src.custom_request_and_route.{request.param}") 1abc

17 

18 client = TestClient(mod.app) 1abc

19 return client 1abc

20 

21 

22def test_get(client: TestClient): 1abdc

23 response = client.get("/") 1hij

24 assert response.json() == {"message": "Not timed"} 1hij

25 assert "X-Response-Time" not in response.headers 1hij

26 

27 

28def test_get_timed(client: TestClient): 1abdc

29 response = client.get("/timed") 1efg

30 assert response.json() == {"message": "It's the time of my life"} 1efg

31 assert "X-Response-Time" in response.headers 1efg

32 assert float(response.headers["X-Response-Time"]) >= 0 1efg