From 24df0289b6c22de1e17df363178e72df49eb2c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 4 Nov 2022 23:44:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Add=20compatibility=20with?= =?UTF-8?q?=20the=20next=20version=20of=20AnyIO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- starlette/testclient.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/starlette/testclient.py b/starlette/testclient.py index 978f8f506..1037e38cb 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -12,6 +12,7 @@ from urllib.parse import unquote, urljoin import anyio +import anyio.from_thread import httpx from anyio.streams.stapled import StapledObjectStream @@ -398,7 +399,9 @@ def _portal_factory(self) -> typing.Generator[anyio.abc.BlockingPortal, None, No if self.portal is not None: yield self.portal else: - with anyio.start_blocking_portal(**self.async_backend) as portal: + with anyio.from_thread.start_blocking_portal( + **self.async_backend + ) as portal: yield portal def _choose_redirect_arg( @@ -714,7 +717,7 @@ def websocket_connect( def __enter__(self) -> "TestClient": with contextlib.ExitStack() as stack: self.portal = portal = stack.enter_context( - anyio.start_blocking_portal(**self.async_backend) + anyio.from_thread.start_blocking_portal(**self.async_backend) ) @stack.callback