-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Async fixtures don't support pytest.mark.usefixtures()
#124
Comments
I guess this has the same cause as #123 -- we're not properly querying pytest to figure out the list of fixtures. I would guess fixing one would also fix the other. |
I just got bit by this too. Min viable reproduction, in case it's useful as a testcase somewhere (though probably not because of the added trio_asyncio dep): import asyncio
import pytest
import trio
import trio_asyncio
@pytest.fixture
async def trio_asyncio_loop():
# When a ^C happens, trio send a Cancelled exception to each running
# coroutine. We must protect this one to avoid deadlock if it is cancelled
# before another coroutine that uses trio-asyncio.
with trio.CancelScope(shield=True):
async with trio_asyncio.open_loop() as loop:
yield loop
@pytest.mark.usefixtures('trio_asyncio_loop')
class TestMetatest:
async def test_the_thing(self):
await trio_asyncio.aio_as_trio(asyncio.sleep)(0) For posterity / any wandering
The workaround is simple, though not DRY: class TestMetatest:
# Explicitly call for the fixture on every test case instead of using mark.usefixtures
async def test_the_thing(self, trio_asyncio_loop):
await trio_asyncio.aio_as_trio(asyncio.sleep)(0) |
Async fixtures can't be used in
@pytest.mark.usefixtures(...)
decorators.I'm sure this is a side-effect of the trio-fixture workaround approach explained in the docs, but it should be possible to examine the test function's marks and honor them.
The text was updated successfully, but these errors were encountered: