MCPcopy
hub / github.com/encode/starlette / test_async_task

Function test_async_task

tests/test_background.py:9–25  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

7
8
9def test_async_task(test_client_factory: TestClientFactory) -> None:
10 TASK_COMPLETE = False
11
12 async def async_task() -> None:
13 nonlocal TASK_COMPLETE
14 TASK_COMPLETE = True
15
16 task = BackgroundTask(async_task)
17
18 async def app(scope: Scope, receive: Receive, send: Send) -> None:
19 response = Response("task initiated", media_type="text/plain", background=task)
20 await response(scope, receive, send)
21
22 client = test_client_factory(app)
23 response = client.get("/")
24 assert response.text == "task initiated"
25 assert TASK_COMPLETE
26
27
28def test_sync_task(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

BackgroundTaskClass · 0.90
test_client_factoryFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected