quart icon indicating copy to clipboard operation
quart copied to clipboard

Allow kwargs in Quart.test_client for custom test client implementations

Open radianer opened this issue 1 year ago • 0 comments

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'

radianer avatar Feb 26 '24 07:02 radianer