Skip to content

Commit 135e3af

Browse files
iudeenKludex
andauthored
Add deprecated warnings to TestClient on use of timeout argument (#2840)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
1 parent 129ccdd commit 135e3af

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

starlette/testclient.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import math
88
import sys
99
import typing
10+
import warnings
1011
from concurrent.futures import Future
1112
from types import GeneratorType
1213
from urllib.parse import unquote, urljoin
@@ -426,6 +427,12 @@ def request( # type: ignore[override]
426427
timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
427428
extensions: dict[str, typing.Any] | None = None,
428429
) -> httpx.Response:
430+
if timeout is not httpx.USE_CLIENT_DEFAULT:
431+
warnings.warn(
432+
"You should not use the 'timeout' argument with the TestClient. "
433+
"See https://github.com/encode/starlette/issues/1108 for more information.",
434+
DeprecationWarning,
435+
)
429436
url = self._merge_url(url)
430437
return super().request(
431438
method,

tests/test_testclient.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,9 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
422422
with client.websocket_connect("/hello-world", params={"foo": "bar"}) as websocket:
423423
data = websocket.receive_bytes()
424424
assert data == b"/hello-world"
425+
426+
427+
def test_timeout_deprecation() -> None:
428+
with pytest.deprecated_call(match="You should not use the 'timeout' argument with the TestClient."):
429+
client = TestClient(mock_service)
430+
client.get("/", timeout=1)

0 commit comments

Comments
 (0)