From 7dd83968c8952dd9d7446e405cfd08786bec871d Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sun, 8 Feb 2026 15:01:54 -0800 Subject: [PATCH 1/2] Docs: update uvloop how-to to avoid deprecated EventLoopPolicy uvloop.EventLoopPolicy was deprecated in uvloop 0.21 and will be removed in Python 3.16. Replace the documented pattern with a minimal custom policy subclass that delegates to uvloop.new_event_loop(), and add a note about the deprecation context and future plans. Closes #1346 Co-Authored-By: Claude Opus 4.6 --- docs/how-to-guides/uvloop.rst | 38 +++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/how-to-guides/uvloop.rst b/docs/how-to-guides/uvloop.rst index a796bea7..2bbb82ba 100644 --- a/docs/how-to-guides/uvloop.rst +++ b/docs/how-to-guides/uvloop.rst @@ -2,17 +2,47 @@ How to test with uvloop ======================= -Redefining the *event_loop_policy* fixture will parametrize all async tests. The following example causes all async tests to run multiple times, once for each event loop in the fixture parameters: -Replace the default event loop policy in your *conftest.py:* +Replace the default event loop policy in your *conftest.py* to run all async +tests with `uvloop `_. + +.. note:: + + ``uvloop.EventLoopPolicy`` is deprecated since uvloop 0.21 and will be + removed in Python 3.16 (see `uvloop#637 + `_). The + ``event_loop_policy`` fixture relies on event loop policies, which are + themselves deprecated as of Python 3.14. A future version of + pytest-asyncio will provide a non-policy-based mechanism for configuring + custom event loops (see `#1164 + `_). + + The pattern below works with current versions of uvloop (< 1.0) and + Python (< 3.16) by wrapping ``uvloop.new_event_loop`` in a minimal + custom policy, avoiding the deprecated ``uvloop.EventLoopPolicy``. .. code-block:: python + import asyncio + import warnings + import pytest import uvloop + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + from asyncio import DefaultEventLoopPolicy + + + class UvloopPolicy(DefaultEventLoopPolicy): + """Minimal policy that uses uvloop's event loop factory.""" + + def new_event_loop(self): + return uvloop.new_event_loop() + @pytest.fixture(scope="session") def event_loop_policy(): - return uvloop.EventLoopPolicy() + return UvloopPolicy() -You may choose to limit the scope of the fixture to *package,* *module,* or *class,* if you only want a subset of your tests to run with uvloop. +You may choose to limit the scope of the fixture to *package,* *module,* or +*class,* if you only want a subset of your tests to run with uvloop. From a144bdfe0d1043e2f4544a448deb5614202bf3a4 Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Wed, 11 Feb 2026 18:55:40 -0800 Subject: [PATCH 2/2] Add changelog entry for uvloop how-to update --- changelog.d/1346.changed.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1346.changed.rst diff --git a/changelog.d/1346.changed.rst b/changelog.d/1346.changed.rst new file mode 100644 index 00000000..a0ea211a --- /dev/null +++ b/changelog.d/1346.changed.rst @@ -0,0 +1 @@ +Updated the uvloop how-to guide to avoid using the deprecated ``uvloop.EventLoopPolicy`` by wrapping ``uvloop.new_event_loop`` in a minimal custom policy