Debian Codegraph @

docs/examples/testing/test_health_check_sync.py

raw
1 from typing import Iterator
2
3 import pytest
4
5 from litestar import Litestar, MediaType, get
6 from litestar.status_codes import HTTP_200_OK
7 from litestar.testing import TestClient
8
9
10 @get(path="/health-check", media_type=MediaType.TEXT, sync_to_thread=False)
11 def health_check() -> str:
12 return "healthy"
13
14
15 app = Litestar(route_handlers=[health_check], debug=True)
16
17
18 @pytest.fixture(scope="function")
19 def test_client() -> Iterator[TestClient[Litestar]]:
20 with TestClient(app=app) as client:
21 yield client
22
23
24 def test_health_check_with_fixture(test_client: TestClient[Litestar]) -> None:
25 response = test_client.get("/health-check")
26 assert response.status_code == HTTP_200_OK
27 assert response.text == "healthy"