(test_client_factory: TestClientFactory)
| 527 | |
| 528 | |
| 529 | def test_middleware_factory(test_client_factory: TestClientFactory) -> None: |
| 530 | calls: list[str] = [] |
| 531 | |
| 532 | def _middleware_factory(app: ASGIApp, arg: str) -> ASGIApp: |
| 533 | async def _app(scope: Scope, receive: Receive, send: Send) -> None: |
| 534 | calls.append(arg) |
| 535 | await app(scope, receive, send) |
| 536 | |
| 537 | return _app |
| 538 | |
| 539 | def get_middleware_factory() -> Callable[[ASGIApp, str], ASGIApp]: |
| 540 | return _middleware_factory |
| 541 | |
| 542 | app = Starlette() |
| 543 | app.add_middleware(_middleware_factory, arg="foo") |
| 544 | app.add_middleware(get_middleware_factory(), "bar") |
| 545 | |
| 546 | with test_client_factory(app): |
| 547 | pass |
| 548 | |
| 549 | assert calls == ["bar", "foo"] |
| 550 | |
| 551 | |
| 552 | def test_lifespan_app_subclass() -> None: |
nothing calls this directly
no test coverage detected