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

How to use the same asyncio.Task between fixtures and each test coroutine so that they can have access to the same scoped db sessions #624

Closed
rinarakaki opened this issue Sep 30, 2023 · 6 comments
Labels
needsinfo Requires additional information from the issue author

Comments

@rinarakaki
Copy link

I've been trying to get the same sqlalchemy.ext.asyncio.AsyncSession instances by sqlalchemy.ext.asyncio.async_scoped_session both from the initialisation methods of the Factory classes and from pytest fixtures provided as function arguments with each testcase. The problem is that the tasks in which the async_scoped_session is called are different, so the sessions provided as fixtures don't hold the pending states flushed by the Factory classes.

@graingert
Copy link
Member

I think this is a dup of #127

@rnarkk have you tried using the anyio pytest plugin? It runs async fixture setup and teardown in the same task

@rinarakaki
Copy link
Author

@graingert Yes, I'm setting pytestmark = pytest.mark.anyio in each test file but seems I need more than that? Do I need to pass some anyio function as scopefunc argument to async_scoped_session to identify current scope?

@rinarakaki
Copy link
Author

Actually anyio doesn't seem to run async fixtures and testcases themselves in the same task.

@seifertm
Copy link
Contributor

seifertm commented Oct 3, 2023

@rnarkk Is there a way you could provide a minimal, runnable reproducer for your problem? Otherwise, it will be hard to pinpoint your problem.

@seifertm seifertm added the needsinfo Requires additional information from the issue author label Oct 3, 2023
@seifertm
Copy link
Contributor

@rnarkk Any update on this topic?

@rinarakaki
Copy link
Author

rinarakaki commented Oct 16, 2023

@seifertm What I've found is when I try to refer contextvars or async_scoped_session from different files, it never was successful so I put both of them in conftest.py then It magically worked. Thank you for check-in.

@seifertm seifertm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needsinfo Requires additional information from the issue author
Projects
None yet
Development

No branches or pull requests

3 participants