Debian Codegraph @

docs/examples/testing/test_subprocess_sse.py

raw
1 """
2 Test the app running in a subprocess
3 """
4
5 import pathlib
6 from typing import AsyncIterator
7
8 import httpx
9 import httpx_sse
10 import pytest
11
12 from litestar.testing import subprocess_async_client
13
14 ROOT = pathlib.Path(__file__).parent
15
16
17 @pytest.fixture(name="async_client")
18 async def fx_async_client() -> AsyncIterator[httpx.AsyncClient]:
19 async with subprocess_async_client(workdir=ROOT, app="subprocess_sse_app:app") as client:
20 yield client
21
22
23 async def test_subprocess_async_client(async_client: httpx.AsyncClient) -> None:
24 """Demonstrates functionality of the async client with an infinite SSE source that cannot be tested with the
25 regular async test client.
26 """
27 topic = "demo"
28
29 async with httpx_sse.aconnect_sse(async_client, "GET", f"/notify/{topic}") as event_source:
30 async for event in event_source.aiter_sse():
31 assert event.data == topic
32 break