-
Notifications
You must be signed in to change notification settings - Fork 12
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
Incompatible with anyio due to event loop keep-alive for session fixtures #119
Comments
I almost wonder if the thread pool option would be preferable to trying to attach to the running loop. dealing with pytest-asyncio has already been a nightmare, and i definitely feel like I've tried to make it work more integratedly before, and it ran into many (potentially pytest-asyncio specific) issues. |
yeah, that could be a good solution |
@gaborbernat Do you know where to (re)place code if you want to run with ThreadPoolExecutor() as thread_pool:
thread_pool.submit(upgrade, alembic_runner).result() |
I never use that flag, so can't tell. |
I am struggling to come up with a setup that works enough to produce the failing behavior. Ideally one of you could make a branch that copies or modifies, say, With my naive attempt at a new test for asyncio (after uninstalling pytest-asyncio, because it appears to not play wel when they're installed together), it either fully succeeds or fails inside of I'll have to look into what precisely anyio is doing, but it seems like the test definitions need to be async functions in order for anyio to do anything with them; and to me that means the default which, i assume, means async def test_upgrade(alembic):
tests.test_upgrade(alembic) only way that will work. I suppose perhaps a |
anyio
creates an event loop during the fixture, and that loop will be reused/kept alive until the fixture is cleaned up (see https://anyio.readthedocs.io/en/stable/testing.html#technical-details). This means that if you have a session scooped fixture (which is quite common, as you might have a DB setup fixture):Then this fixture will keep alive the event loop until the end of the session (such fixture requires all your tests using the DB to reuse the same event loop).
pytest-alembic
, however, assumes that when its test is running, there is no other event loop running, as it is callingpytest-alembic/src/pytest_alembic/executor.py
Line 182 in 5ff6ca0
Instead,
pytest-alembic
IMHO should check if there is a live event loop and reuse it if so. A working workaround for now would be to create a new thread (that by default has no running loop on it):The text was updated successfully, but these errors were encountered: