Skip to content

Remove deprecated event_loop_policy fixture - #1517

Open
seifertm wants to merge 2 commits into
pytest-dev:mainfrom
seifertm:remove-event-loop-policy
Open

Remove deprecated event_loop_policy fixture#1517
seifertm wants to merge 2 commits into
pytest-dev:mainfrom
seifertm:remove-event-loop-policy

Conversation

@seifertm

Copy link
Copy Markdown
Contributor

The asyncio policy system has been deprecated and is scheduled for removal in CPython 3.16. The pytest-asyncio policy system is deprecated and has been superseeded by the pytest_asyncio_loop_factory hook.

This PR removes the deprecated event_loop_policy fixture.

Obsoletes #796

@seifertm
seifertm requested review from Tinche and asvetlov as code owners July 21, 2026 13:03
@seifertm
seifertm requested review from tjkuson and removed request for Tinche and asvetlov July 21, 2026 13:03
@seifertm
seifertm force-pushed the remove-event-loop-policy branch from e658814 to ba9c3f8 Compare July 21, 2026 13:06
@seifertm seifertm added this to the v2.0 milestone Jul 21, 2026
@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.42%. Comparing base (054a52d) to head (2ac8576).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1517      +/-   ##
==========================================
- Coverage   94.50%   94.42%   -0.09%     
==========================================
  Files           2        2              
  Lines         510      502       -8     
  Branches       62       61       -1     
==========================================
- Hits          482      474       -8     
  Misses         22       22              
  Partials        6        6              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

seifertm added 2 commits July 21, 2026 15:41
The function no longer needs the event loop policy to be passed as an argument. It always restores the currently installed policy.
@seifertm
seifertm force-pushed the remove-event-loop-policy branch from ba9c3f8 to 2ac8576 Compare July 21, 2026 13:53
Comment thread pytest_asyncio/plugin.py
def _temporary_event_loop_policy(
policy: AbstractEventLoopPolicy,
) -> Iterator[None]:
def _restore_event_loop_policy() -> Iterator[None]:

@edgarrmondragon edgarrmondragon Aug 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this context manager be outright removed? It still calls deprecated/removed APIs and all tests under Python 3.14 and 3.16 pass when I don't use it in _create_scoped_runner_fixture.

@tjkuson tjkuson Aug 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this offline at the pytest sprint. I think there are merits to either approach.

The idea was that code under test might apply an event loop policy which will need to be restored between tests even if we remove support for configuring the policy via the pytest-asyncio fixture. If we remove policy restoration context manager, users who depend on event loop policy being reset between tests could see confusing errors when upgrading to this new version (independent of the deprecated loop policy fixture being removed).

However, getting a warning about the deprecated API even after we ostensibly remove support for it is also a bad user experience. It might be strong enough reason to remove the support for event loop policies entirely.

If we remove both the fixture and the feature of the plugin that reset the policy between tests, then we'd need to communicate to users that both the fixture and support for testing code that sets an event loop policy are unsupported in v2.

@edgarrmondragon edgarrmondragon Aug 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context! So perhaps there is a compromise where the current policy is guarded and restored only on Python < 3.16, since users won't presumably be able to apply any policies on 3.16+ anyway. But perhaps that's thinking way too ahead of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants