(test_client_factory: TestClientFactory)
| 691 | |
| 692 | |
| 693 | def 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 | |
| 717 | def test_raise_on_shutdown(test_client_factory: TestClientFactory) -> None: |
nothing calls this directly
no test coverage detected