From dbed8ad8ce348dd89ac6f8c69e7807ab16404bbe Mon Sep 17 00:00:00 2001 From: FlorianRegaz Date: Sat, 10 Oct 2026 17:32:13 +0200 Subject: [PATCH] Accept both messages Go uses for a timeout in the timeout tests The library reports a timeout as "Client.Timeout exceeded" or "context deadline exceeded" depending on where the deadline hits, so the tests failed at random on Ubuntu runners. Co-Authored-By: Claude Opus 5.5 --- tests/integration/test_httpbin.py | 7 +++++-- tests/integration/test_local_server.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_httpbin.py b/tests/integration/test_httpbin.py index 422f7e2..53da40e 100644 --- a/tests/integration/test_httpbin.py +++ b/tests/integration/test_httpbin.py @@ -11,6 +11,9 @@ pytestmark = pytest.mark.integration +# Go reports a timeout as "Client.Timeout exceeded" or "context deadline exceeded", depending on where it hits. +TIMEOUT = "Timeout exceeded|deadline exceeded" + @pytest.fixture def session() -> Iterator[Session]: @@ -241,14 +244,14 @@ def test_refused_connection_raises(self, session): def test_session_timeout_raises(self, httpbin, session): session.timeout_seconds = 1 - with pytest.raises(TLSClientException, match="Timeout exceeded"): + with pytest.raises(TLSClientException, match=TIMEOUT): session.get(f"{httpbin.url}/delay/2") @pytest.mark.parametrize("kwarg", ["timeout", "timeout_seconds"]) def test_request_timeout_applies_after_the_first_request(self, httpbin, session, kwarg): session.get(f"{httpbin.url}/get") - with pytest.raises(TLSClientException, match="Timeout exceeded"): + with pytest.raises(TLSClientException, match=TIMEOUT): session.get(f"{httpbin.url}/delay/2", **{kwarg: 1}) diff --git a/tests/integration/test_local_server.py b/tests/integration/test_local_server.py index ca23c69..a6d9dcf 100644 --- a/tests/integration/test_local_server.py +++ b/tests/integration/test_local_server.py @@ -24,6 +24,8 @@ LARGE = os.urandom(8 * 1024 * 1024) # How long /slow takes to answer. SLOW_SECONDS = 0.6 +# Go reports a timeout as "Client.Timeout exceeded" or "context deadline exceeded", depending on where it hits. +TIMEOUT = "Timeout exceeded|deadline exceeded" # Path -> (Content-Type, body) BODIES = { @@ -166,7 +168,7 @@ def test_content_type_from_the_session_or_the_request_is_kept(self, server_url, class TestTimeout: @pytest.mark.parametrize("kwarg", ["timeout", "timeout_seconds"]) def test_fractional_timeout_is_applied(self, server_url, session, kwarg): - with pytest.raises(TLSClientException, match="Timeout exceeded"): + with pytest.raises(TLSClientException, match=TIMEOUT): session.get(f"{server_url}/slow", **{kwarg: SLOW_SECONDS / 3}) def test_response_within_the_timeout_arrives(self, server_url, session): @@ -175,7 +177,7 @@ def test_response_within_the_timeout_arrives(self, server_url, session): def test_fractional_session_timeout_is_applied(self, server_url, session): session.timeout_seconds = SLOW_SECONDS / 3 - with pytest.raises(TLSClientException, match="Timeout exceeded"): + with pytest.raises(TLSClientException, match=TIMEOUT): session.get(f"{server_url}/slow")