quart
quart copied to clipboard
Allow kwargs in Quart.test_client for custom test client implementations
Allow kwargs in the Quart.test_client like in Flask.test_client, to pass custom parameters to custom test client implementations.
class CustomClient(QuartClient):
def __init__(self, *args: Any, **kwargs: Any) -> None:
self._authorization = kwargs.pop("authorization")
super().__init__(*args, **kwargs)
@override
async def open(self, *args: Any, **kwargs: Any) -> TestResponse:
if self._authorization:
headers = kwargs.setdefault("headers", {})
headers["Authorization"] = f"Bearer {self._authorization}"
return await super().open(*args, **kwargs)
app = Quart()
app_instance.test_client_class = CustomClient
test_client = app.test_client(authorization="abc123")
Error:
TypeError: Quart.test_client() got an unexpected keyword argument 'authorization'