'Anyio' Has No Attribute 'Start_Blocking_Portal'

One of my fast api endpoints is supposed to return a csv response. I try to check this endpoint but I get this error

self = <starlette.testclient.TestClient object at 0x7f834a5f6ec0>

    @contextlib.contextmanager
    def _portal_factory(
        self,
    ) -> typing.Generator[anyio.abc.BlockingPortal, None, None]:
        if self.portal is not None:
            yield self.portal
        else:
>           with anyio.start_blocking_portal(**self.async_backend) as portal:
E           AttributeError: module 'anyio' has no attribute 'start_blocking_portal'

This is how the test look like

from starlette.testclient import TestClient


def test_endpoint(client: TestClient, file_regression):

    response = client.get("/bla")

    file_regression.check(response.content, extension=".csv", binary=True)

my requirements.txt

black
fastapi==0.85.0
isort
pytest
pytest-regressions
requests
uvicorn

1 Answer

I see that start_blocking_portal is in anyio.from_thread package in stable version.

start_blocking_portal is in anyio package in v2.x

And I recommend you to upgrade FastAPI version to the current release

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest