Skip to content

Commit

Permalink
♻️ Add compatibility with the next version of AnyIO (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Nov 4, 2022
1 parent fbab16a commit a450272
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions starlette/testclient.py
Expand Up @@ -12,6 +12,7 @@
from urllib.parse import unquote, urljoin

import anyio
import anyio.from_thread
import httpx
from anyio.streams.stapled import StapledObjectStream

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a450272

Please sign in to comment.