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

Allow independent caching scope and event loop scopes for async fixtures #871

Merged
merged 11 commits into from
Jul 30, 2024

Conversation

seifertm
Copy link
Contributor

@seifertm seifertm commented Jul 5, 2024

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.

@codecov-commenter
Copy link

codecov-commenter commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 90.62500% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.86%. Comparing base (a56bb3f) to head (5f34edf).
Report is 78 commits behind head on main.

Files with missing lines Patch % Lines
pytest_asyncio/plugin.py 90.62% 1 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

@seifertm
Copy link
Contributor Author

I decided not to add an automatic migration tool for the deprecation of pytest.mark.asyncio(scope=…), because a global search and replace should do the trick just as well.

bmerry added a commit to ska-sa/katgpucbf that referenced this pull request Jul 24, 2024
This should not be merged until that PR is released and we switch to that
version (probably 0.24).
Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…re with additional pytest fixture scopes.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…nvert_async_functions_to_subclass.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…ion.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…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 <m.seifert@digitalernachschub.de>
Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…all fixtures.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…the loop_scope keyword argument.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
@seifertm seifertm marked this pull request as ready for review July 25, 2024 07:56
@seifertm
Copy link
Contributor Author

Should we add a migration guide?

@seifertm seifertm added this pull request to the merge queue Jul 30, 2024
Merged via the queue into pytest-dev:main with commit 13e8f25 Jul 30, 2024
17 checks passed
@seifertm seifertm deleted the fixture-loop-scope branch July 30, 2024 12:30
lossyrob added a commit to lossyrob/semantic-kernel that referenced this pull request Oct 7, 2024
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.
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

Successfully merging this pull request may close these issues.

2 participants