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

Function test_exception_in_middleware

tests/test_testclient.py:180–195  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

178
179
180def test_exception_in_middleware(test_client_factory: TestClientFactory) -> None:
181 class MiddlewareException(Exception):
182 pass
183
184 class BrokenMiddleware:
185 def __init__(self, app: ASGIApp):
186 self.app = app
187
188 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
189 raise MiddlewareException()
190
191 broken_middleware = Starlette(middleware=[Middleware(BrokenMiddleware)])
192
193 with pytest.raises(MiddlewareException):
194 with test_client_factory(broken_middleware):
195 pass # pragma: no cover
196
197
198def test_testclient_asgi2(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

StarletteClass · 0.90
MiddlewareClass · 0.90
test_client_factoryFunction · 0.85

Tested by

no test coverage detected