Closed vlcinsky closed 6 years ago
I see no pool
fixture in your code
@asvetlov thanks for heads up, I meant loop
(not pool
). I fixed the description.
This has also caused me some headaches as well when trying to write tests and having both pytest-aiohttp
and pytest-asyncio
installed. So far I've been the most successful with redefining the loop
fixture to use the event_loop
fixture as mentioned here.
me too;
At least it seems like I can reasonably get away with using only pytest-aiohttp and just skip pytest-asyncio entirely. So not that big a problem. Just time wasting and confusing for developers.
While it's nice that many people can get away with only using the pytest-aiohttp plugin, I don't think this is always possible. I can double check if necessary, but I remember a case where I couldn't just use the aiohttp plugin. I think it was a test that didn't use any aiohttp fixtures and was just a simple async test and got some exception.
Sorry for the worst description ever, but if it would be useful I can try to reproduce what I was seeing.
I think I've encouter same issue with a shorted code using ThreadPoolExecutor without redis.
It seems that I can't use loop
fixture from pytest-aiohttp
while pytest-asyncio > 0.5.0
is installed.
Following source using event_loop
fixture from pytest-asyncio
is working fine with pytest-asyncio == 0.8.0
installed :
import asyncio
import pytest
from concurrent.futures import ThreadPoolExecutor
def count():
return 0
@pytest.fixture
async def my_fixture(event_loop):
executor = ThreadPoolExecutor()
await event_loop.run_in_executor(executor, count)
async def test_f(my_fixture):
pass
Following source with loop
fixture from pytest-aiohttp
:
pytest-asyncio == 0.5.0
is installed pytest-asyncio == 0.8.0
is installedimport asyncio
import pytest
from concurrent.futures import ThreadPoolExecutor
def count():
return 0
@pytest.fixture
async def my_fixture(loop):
executor = ThreadPoolExecutor()
await loop.run_in_executor(executor, count)
async def test_f(my_fixture):
pass
pytest-asyncio
and pytest-aiohttp
libraries are not compatible.
That's sad but we should live with it.
Having following test file, things behave differently with different pytest plugins installed:
only
pytest-aiohttp
installed: all is fineWhen only
pytest-aiohttp
is installed, the test runs well as it is.with
pytest-asyncio
, it failsWhen also
pytest-asyncio
is installed, the test fails with:fix by masking
loop
fixtureTo fix this problem (still using
pytest-asyncio
plugin), one has to uncomment theloop
fixture.