From 356ff4122ca97722022bcd79f4b774b150b04966 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 15 Dec 2023 13:40:06 +0000 Subject: [PATCH] fix sync do_request().stream --- tests/integration/test_httpx.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_httpx.py b/tests/integration/test_httpx.py index d81b065..39d6131 100644 --- a/tests/integration/test_httpx.py +++ b/tests/integration/test_httpx.py @@ -51,8 +51,14 @@ class DoSyncRequest(BaseDoRequest): return self.client.request(*args, timeout=60, **kwargs) def stream(self, *args, **kwargs): - with self.client.stream(*args, **kwargs) as response: - return b"".join(response.iter_bytes()) + if hasattr(self, "_client"): + with self.client.stream(*args, **kwargs) as response: + return b"".join(response.iter_bytes()) + + # Use one-time context and dispose of the client afterwards + with self: + with self.client.stream(*args, **kwargs) as response: + return b"".join(response.iter_bytes()) class DoAsyncRequest(BaseDoRequest):