-
Notifications
You must be signed in to change notification settings - Fork 152
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
Allow independent caching scope and event loop scopes for async fixtures #871
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #871 +/- ##
==========================================
- Coverage 92.09% 91.86% -0.24%
==========================================
Files 2 2
Lines 481 504 +23
Branches 96 99 +3
==========================================
+ Hits 443 463 +20
- Misses 23 24 +1
- Partials 15 17 +2 ☔ View full report in Codecov by Sentry. |
8daa107
to
9d4ad54
Compare
I decided not to add an automatic migration tool for the deprecation of |
This should not be merged until that PR is released and we switch to that version (probably 0.24).
7f802bb
to
add4d67
Compare
Signed-off-by: Michael Seifert <[email protected]>
…re with additional pytest fixture scopes. Signed-off-by: Michael Seifert <[email protected]>
…nvert_async_functions_to_subclass. Signed-off-by: Michael Seifert <[email protected]>
…ion. Signed-off-by: Michael Seifert <[email protected]>
…rkers. Users are encouraged to use the `loop_scope` keyword argument. The `loop_scope` kwarg does exactly the same, though its naming is consistent with the `loop_scope` kwarg of ``pytest_asyncio.fixture``. Signed-off-by: Michael Seifert <[email protected]>
Signed-off-by: Michael Seifert <[email protected]>
…all fixtures. Signed-off-by: Michael Seifert <[email protected]>
…the loop_scope keyword argument. Signed-off-by: Michael Seifert <[email protected]>
add4d67
to
a4d64c8
Compare
Signed-off-by: Michael Seifert <[email protected]>
Should we add a migration guide? |
With the current version of pytest-asyncio we're using, there's an issue with using async fixtures cached at different scopes when they need the same event loop scope. See: pytest-dev/pytest-asyncio#871 An API breaking change that fixes this is available in 0.24, but fixing this with a context manager here to avoid increasing the blast radius.
Pytest-asyncio v0.23 assumes that the event loop scope of a fixture is the same as the caching scope (as in
@pytest.fixture(scope="…")
). This causes problems when fixtures should be cached (e.g. session wide database setup), but the fixture should be run in a differently scoped event loop (e.g. module-scoped loop) or when multiple async fixtures should be used together with different caching scopes.Deal with mismatching loop scopes of two fixtures used in the same test (see Breaking change in 0.23.* #706 (comment))superseded by Improve detection of multiple event loops being requested in a test #873@pytest.mark.asyncio(scope="…")
in favour of@pytest.mark.asyncio(loop_scope="…")
Provide automatic migration tool for the above deprecation?