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

Async fixtures do not support autouse=True #123

Open
mikenerone opened this issue Sep 7, 2021 · 2 comments
Open

Async fixtures do not support autouse=True #123

mikenerone opened this issue Sep 7, 2021 · 2 comments

Comments

@mikenerone
Copy link
Member

mikenerone commented Sep 7, 2021

Async fixtures defined with autouse aren't automatically used. E.g.

@pytest.fixture(autouse=True):
async def clear_some_db_table():
    ...

I'm sure this is a side-effect of the trio-fixture workaround approach explained in the docs, but it still might be possible to find those fixtures and make them work. If not, I think this rub is at least worth specifically mentioning in the docs.

@mikenerone mikenerone changed the title Async fixture do not support autouse=True Async fixture do not support autouse=True Sep 7, 2021
@mikenerone mikenerone changed the title Async fixture do not support autouse=True Async fixtures do not support autouse=True Sep 7, 2021
@njsmith
Copy link
Member

njsmith commented Sep 8, 2021

I think the issue is that when we scan through to find and run all the trio fixtures, we do that by scanning over the test's kwargs, and I guess autouse fixtures don't show up in kwargs? The relevant code is in plugin.py, _trio_test_runner_factory which delegates to register_and_collect_dependencies. It's probably easy to fix -- we just need to figure out some way to query pytest for the full list of fixtures, not just the ones that get passed into the test function. Likely it's stashed on the item object somewhere? That's this magical pytest thing that has all kinds of undocumented attributes on it.

@jakkdl
Copy link
Member

jakkdl commented Sep 17, 2024

This does work with pytest-anyio, so we can likely just copy over the relevant code from over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants