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

Function test_lifespan_state_unsupported

tests/test_routing.py:626–642  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

624
625
626def test_lifespan_state_unsupported(test_client_factory: TestClientFactory) -> None:
627 @contextlib.asynccontextmanager
628 async def lifespan(app: ASGIApp) -> AsyncGenerator[dict[str, str], None]:
629 yield {"foo": "bar"}
630
631 app = Router(
632 lifespan=lifespan,
633 routes=[Mount("/", PlainTextResponse("hello, world"))],
634 )
635
636 async def no_state_wrapper(scope: Scope, receive: Receive, send: Send) -> None:
637 del scope["state"]
638 await app(scope, receive, send)
639
640 with pytest.raises(RuntimeError, match='The server does not support "state" in the lifespan scope'):
641 with test_client_factory(no_state_wrapper):
642 raise AssertionError("Should not be called") # pragma: no cover
643
644
645def test_lifespan_state_async_cm(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 4

RouterClass · 0.90
MountClass · 0.90
PlainTextResponseClass · 0.90
test_client_factoryFunction · 0.85

Tested by

no test coverage detected