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

Introduce event_loop_policy fixture #662

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

seifertm
Copy link
Contributor

@seifertm seifertm commented Nov 3, 2023

This PR introduces the new fixture event_loop_policy. The fixture returns an instance of an asyncio.AbstractEventLoopPolicy. By default, the fixture has session (i.e. it is accessible by all tests) and returns the value of asyncio.get_event_loop_policy().

Users can run pytest-asyncio tests with different types of event loops by redefining the fixture to return a different event loop policy. Parametrizing the fixture causes pytest-asyncio tests to be run once for each specified policy. This allows writing tests against multiple different types of event loops.

Although the concept of event loop policies is likely going to be deprecated in CPython 3.13, it was decided that this functionality is still going to land in pytest-asyncio. Starting with CPython 3.13, pytest-asyncio will provide a migration path for the deprecated policy system.

Resolves #591
Prerequisite for #657

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (973eaa4) 94.08% compared to head (9c2b996) 94.31%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #662      +/-   ##
==========================================
+ Coverage   94.08%   94.31%   +0.22%     
==========================================
  Files           2        2              
  Lines         406      422      +16     
  Branches       87       89       +2     
==========================================
+ Hits          382      398      +16     
  Misses         14       14              
  Partials       10       10              
Files Coverage Δ
pytest_asyncio/plugin.py 94.27% <100.00%> (+0.22%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seifertm seifertm force-pushed the support-for-larger-loop-scopes branch 2 times, most recently from a327200 to 683ce86 Compare November 5, 2023 15:37
@Tinche
Copy link
Member

Tinche commented Nov 5, 2023

Since I'm active on DPO, I just wanted to make sure you're aware of tentative plans to deprecate event loop policies in general (https://discuss.python.org/t/removing-the-asyncio-policy-system-asyncio-set-event-loop-policy-in-python-3-15/37553). From what I can tell, nothing has been decided yet, just bringing this to your attention.

Although I think the idea here is sound. If event loop policies are deprecated, we could allow users to override a different fixture (event_loop_configuration?) to apply simple customizations to event loops without overriding the event_loop fixture itself.

@seifertm
Copy link
Contributor Author

seifertm commented Nov 6, 2023

Thanks for mentioning the policy deprecation!

The topic was also touched in #657 (comment) ff.
My takeaway from this thread was that we don't need to deprecate things faster than upstream.

If you also think the approach is generally sound, I'll continue to pursue this.

@seifertm seifertm force-pushed the support-for-larger-loop-scopes branch 4 times, most recently from c064c33 to 48cad08 Compare November 8, 2023 14:18
@seifertm seifertm changed the title WIP: Introduce event_loop_policy fixture. Introduce event_loop_policy fixture Nov 8, 2023
@seifertm seifertm force-pushed the support-for-larger-loop-scopes branch 3 times, most recently from 9eef86b to c93fdd8 Compare November 8, 2023 14:43
@seifertm seifertm marked this pull request as ready for review November 8, 2023 14:49
@seifertm seifertm force-pushed the support-for-larger-loop-scopes branch from c93fdd8 to 9c2b996 Compare November 10, 2023 08:06
@seifertm seifertm added this pull request to the merge queue Nov 10, 2023
Merged via the queue into pytest-dev:main with commit 4c5e660 Nov 10, 2023
9 checks passed
@seifertm seifertm deleted the support-for-larger-loop-scopes branch November 10, 2023 08:11
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.

Unexpected behavior when defining custom loop policy
3 participants