Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated warnings to TestClient on use of timeout argument #2840

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading