Skip to content

sniffio fails to detect asyncio when run via twisted internet asyncio reactor #51

@BrynGibson

Description

@BrynGibson

I have been experimenting with using httpx as an async http client and have built an api client around this. I have been attempting to run test cases using twisted trial unittests. However running this fails as get an error with sniffio failing to detect that it is within an asyncio event loop.

Here is an example of showing what causes the error.

from twisted.trial import unittest
from foo import APIClientAsync


import asyncio
from twisted.internet import asyncioreactor
asyncioreactor.install(asyncio.get_event_loop())

class TestAPIClient(unittest.TestCase):

    def setUp(self):
        self.client = APIClientAsync()


    async def test_client(self):

        result = await self.client.request()

This will give the following error:

sniffio/_impl.py", line 93, in current_async_library raise AsyncLibraryNotFoundError( sniffio._impl.AsyncLibraryNotFoundError: unknown async library, or not in async context

Is this a known error, or is there any known workaround for this? Or should I switch to a different testing framework to enable asyncio detection?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions