Created
September 2, 2020 14:19
-
-
Save dmajda/83e24a018c0000c1093d58422c384bc0 to your computer and use it in GitHub Desktop.
Files reproducing a bug in `pytest-asyncio`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains files reproducing a bug in `pytest-asyncio` that appears | |
when testing an aiohttp application. The bug is a regression. The last good | |
version is 0.12.0, the first bad version is 0.14.0 (it looks like there is no | |
0.13.0). | |
Without the bug: | |
```console | |
$ pip3 install -r requirements-0.12.0.txt | |
$ pytest > pytest-output-0.12.0.txt | |
With the bug: | |
```console | |
$ pip3 install -r requirements-0.14.0.txt | |
$ pytest > pytest-output-0.14.0.txt | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================= test session starts ============================== | |
platform darwin -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 | |
rootdir: /Users/dmajda/tmp/pytest-asyncio-test | |
plugins: asyncio-0.12.0, aiohttp-0.3.0 | |
collected 1 item | |
test_app.py . [100%] | |
=============================== warnings summary =============================== | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/connector.py:964: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10. | |
hosts = await asyncio.shield(self._resolve_host( | |
-- Docs: https://docs.pytest.org/en/stable/warnings.html | |
========================= 1 passed, 1 warning in 0.04s ========================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
============================= test session starts ============================== | |
platform darwin -- Python 3.8.5, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 | |
rootdir: /Users/dmajda/tmp/pytest-asyncio-test | |
plugins: aiohttp-0.3.0, asyncio-0.14.0 | |
collected 1 item | |
test_app.py F [100%] | |
=================================== FAILURES =================================== | |
______________________________ test_ping[pyloop] _______________________________ | |
aiohttp_client = <function aiohttp_client.<locals>.go at 0x10ddf6af0> | |
@pytest.mark.asyncio | |
async def test_ping(aiohttp_client): | |
async def handle_ping(request): | |
return web.Response(text='pong') | |
app = web.Application() | |
app.router.add_get('/ping', handle_ping) | |
client = await aiohttp_client(app) | |
> response = await client.get('/ping') | |
test_app.py:14: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
.venv/lib/python3.8/site-packages/aiohttp/test_utils.py:291: in _request | |
resp = await self._session.request( | |
.venv/lib/python3.8/site-packages/aiohttp/client.py:426: in _request | |
with timer: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <aiohttp.helpers.TimerContext object at 0x10de0fc70> | |
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 | |
.venv/lib/python3.8/site-packages/aiohttp/helpers.py:579: RuntimeError | |
=============================== warnings summary =============================== | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/cookiejar.py:55: DeprecationWarning: The object should be created from async function | |
super().__init__(loop=loop) | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/test_utils.py:249: DeprecationWarning: The object should be created from async function | |
self._session = ClientSession(loop=loop, | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/connector.py:727: DeprecationWarning: The object should be created from async function | |
super().__init__(keepalive_timeout=keepalive_timeout, | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/connector.py:736: DeprecationWarning: The object should be created from async function | |
resolver = DefaultResolver(loop=self._loop) | |
test_app.py::test_ping[pyloop] | |
/Users/dmajda/tmp/pytest-asyncio-test/.venv/lib/python3.8/site-packages/aiohttp/web_server.py:53: DeprecationWarning: The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10. | |
await asyncio.gather(*coros, loop=self._loop) | |
-- Docs: https://docs.pytest.org/en/stable/warnings.html | |
=========================== short test summary info ============================ | |
FAILED test_app.py::test_ping[pyloop] - RuntimeError: Timeout context manager... | |
======================== 1 failed, 5 warnings in 0.18s ========================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aiohttp==3.6.2 | |
pytest==6.0.1 | |
pytest-aiohttp==0.3.0 | |
pytest-asyncio==0.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aiohttp==3.6.2 | |
pytest==6.0.1 | |
pytest-aiohttp==0.3.0 | |
pytest-asyncio==0.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from aiohttp import web | |
@pytest.mark.asyncio | |
async def test_ping(aiohttp_client): | |
async def handle_ping(request): | |
return web.Response(text='pong') | |
app = web.Application() | |
app.router.add_get('/ping', handle_ping) | |
client = await aiohttp_client(app) | |
response = await client.get('/ping') | |
assert response.status == 200 | |
assert await response.text() == 'pong' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment