diff --git a/starlette/testclient.py b/starlette/testclient.py index fb2ad6e35..5b0b855c7 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -7,6 +7,7 @@ import math import sys import typing +import warnings from concurrent.futures import Future from types import GeneratorType from urllib.parse import unquote, urljoin @@ -426,6 +427,8 @@ def request( # type: ignore[override] timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT, extensions: dict[str, typing.Any] | None = None, ) -> httpx.Response: + if timeout is not httpx.USE_CLIENT_DEFAULT: + warnings.warn("The 'timeout' argument is not supported by 'TestClient'.", DeprecationWarning) url = self._merge_url(url) return super().request( method, diff --git a/tests/test_testclient.py b/tests/test_testclient.py index 478dbca46..5d8a4fbf2 100644 --- a/tests/test_testclient.py +++ b/tests/test_testclient.py @@ -422,3 +422,12 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None: with client.websocket_connect("/hello-world", params={"foo": "bar"}) as websocket: data = websocket.receive_bytes() assert data == b"/hello-world" + + +@pytest.mark.parametrize("method", ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) +def test_timeout_deprecation(method: str) -> None: + with pytest.deprecated_call(): + client = TestClient(mock_service) + client.request(method, "/", timeout=1) + method_call = getattr(client, method.lower()) + method_call("/", timeout=1)