Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency on pytest-asyncio breaks support for aiohttp #52

Closed
elupus opened this issue Oct 2, 2020 · 3 comments · Fixed by #57
Closed

Dependency on pytest-asyncio breaks support for aiohttp #52

elupus opened this issue Oct 2, 2020 · 3 comments · Fixed by #57

Comments

@elupus
Copy link

elupus commented Oct 2, 2020

When trying to run a test with the workaround provided for compatibility with aiohttp, the test fail with an error:

Test session starts (platform: darwin, Python 3.7.3, pytest 5.4.1, pytest-sugar 0.9.3)
rootdir: /Users/joakim/src/hass/nibeuplink
plugins: timeout-1.3.4, aresponses-2.0.0, mock-3.1.0, requests-mock-1.7.0, sugar-0.9.3, cov-2.5.1, threadleak-0.2.0, aiohttp-0.3.0, asyncio-0.14.0
collecting ... 

――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_get_system ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

aresponses = <aresponses.main.ResponsesMockServer object at 0x10745a978>, uplink = <nibeuplink.uplink.Uplink object at 0x10745ac18>

    async def test_get_system(aresponses, uplink: Uplink):
>       result = await uplink.get_system(123)

tests/test_uplink.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/nibeuplink/uplink.py:175: in get_system
    return await self.get(f"systems/{system_id}")
src/nibeuplink/uplink.py:74: in get
    "GET", f"{self.base}/api/v1/{url}", *args, **kwargs
src/nibeuplink/session.py:175: in request
    response = await self.session.request(*args, auth=await self._get_auth(), **kw)
../home-assistant/venv/lib/python3.7/site-packages/aiohttp/client.py:426: in _request
    with timer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <aiohttp.helpers.TimerContext object at 0x10745a0f0>

    def __enter__(self) -> BaseTimerContext:
        task = current_task(loop=self._loop)
    
        if task is None:
>           raise RuntimeError('Timeout context manager should be used '
                               'inside a task')
E           RuntimeError: Timeout context manager should be used inside a task

../home-assistant/venv/lib/python3.7/site-packages/aiohttp/helpers.py:579: RuntimeError

 tests/test_uplink.py ⨯                                                                                                                                                          100% ██████████
=================================================================================== short test summary info ====================================================================================
FAILED tests/test_uplink.py::test_get_system - RuntimeError: Timeout context manager should be used inside a task

After doing a pip uninstall pytest-asyncio, the test succeeds. Just having pytest-asyncio installed breaks behavior of aiohttp tests.

Would it be possible to have aresponses check which pytest aio handler is installed and use the loop accordingly, then drop the requirement from setup.py (or make it either or).

@elupus
Copy link
Author

elupus commented Oct 2, 2020

This is pretty much a duplicate of: #26

@brycedrennan
Copy link
Collaborator

Looks like a bug with pytest-asyncio https://github.com/pytest-dev/pytest-asyncio/issues?q=is%3Aopen+is%3Aissue

@brycedrennan
Copy link
Collaborator

@elupus I'm not sure I understand. Could you post an example of the test code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants