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

Function test_raise_on_startup

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

Source from the content-addressed store, hash-verified

691
692
693def test_raise_on_startup(test_client_factory: TestClientFactory) -> None:
694 @contextlib.asynccontextmanager
695 async def lifespan(app: Starlette) -> AsyncIterator[Never]:
696 raise RuntimeError()
697 yield # pragma: no cover
698
699 router = Router(lifespan=lifespan)
700 startup_failed = False
701
702 async def app(scope: Scope, receive: Receive, send: Send) -> None:
703 async def _send(message: Message) -> None:
704 nonlocal startup_failed
705 if message["type"] == "lifespan.startup.failed": # pragma: no branch
706 startup_failed = True
707 return await send(message)
708
709 await router(scope, receive, _send)
710
711 with pytest.raises(RuntimeError):
712 with test_client_factory(app):
713 pass # pragma: no cover
714 assert startup_failed
715
716
717def test_raise_on_shutdown(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 2

RouterClass · 0.90
test_client_factoryFunction · 0.85

Tested by

no test coverage detected