(test_client_factory: TestClientFactory)
| 505 | |
| 506 | |
| 507 | def test_middleware_args(test_client_factory: TestClientFactory) -> None: |
| 508 | calls: list[str] = [] |
| 509 | |
| 510 | class MiddlewareWithArgs: |
| 511 | def __init__(self, app: ASGIApp, arg: str) -> None: |
| 512 | self.app = app |
| 513 | self.arg = arg |
| 514 | |
| 515 | async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: |
| 516 | calls.append(self.arg) |
| 517 | await self.app(scope, receive, send) |
| 518 | |
| 519 | app = Starlette() |
| 520 | app.add_middleware(MiddlewareWithArgs, "foo") |
| 521 | app.add_middleware(MiddlewareWithArgs, "bar") |
| 522 | |
| 523 | with test_client_factory(app): |
| 524 | pass |
| 525 | |
| 526 | assert calls == ["bar", "foo"] |
| 527 | |
| 528 | |
| 529 | def test_middleware_factory(test_client_factory: TestClientFactory) -> None: |
nothing calls this directly
no test coverage detected