[Python-checkins] Fix warning: asyncio.events._event_loop_policy was modified by test_asyncio (GH-31253)

asvetlov webhook-mailer at python.org
Thu Feb 10 07:57:26 EST 2022


https://github.com/python/cpython/commit/012e77eb5c3ba3d411f5967a7f368ebdb42ab88c
commit: 012e77eb5c3ba3d411f5967a7f368ebdb42ab88c
branch: main
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: asvetlov <andrew.svetlov at gmail.com>
date: 2022-02-10T14:57:20+02:00
summary:

Fix warning: asyncio.events._event_loop_policy was modified by test_asyncio (GH-31253)

files:
A Misc/NEWS.d/next/Tests/2022-02-10-14-33-47.bpo-46708.avLfCb.rst
M Lib/test/test_asyncio/test_futures2.py
M Lib/test/test_asyncio/test_protocols.py
M Lib/test/test_asyncio/test_runners.py
M Lib/test/test_asyncio/test_sock_lowlevel.py
M Lib/test/test_asyncio/test_transports.py
M Lib/test/test_asyncio/test_unix_events.py

diff --git a/Lib/test/test_asyncio/test_futures2.py b/Lib/test/test_asyncio/test_futures2.py
index 57d24190bc0bd..60b58850369f0 100644
--- a/Lib/test/test_asyncio/test_futures2.py
+++ b/Lib/test/test_asyncio/test_futures2.py
@@ -3,6 +3,10 @@
 import unittest
 
 
+def tearDownModule():
+    asyncio.set_event_loop_policy(None)
+
+
 class FutureTests(unittest.IsolatedAsyncioTestCase):
     async def test_recursive_repr_for_pending_tasks(self):
         # The call crashes if the guard for recursive call
diff --git a/Lib/test/test_asyncio/test_protocols.py b/Lib/test/test_asyncio/test_protocols.py
index d8cde6d89aadc..0f232631867db 100644
--- a/Lib/test/test_asyncio/test_protocols.py
+++ b/Lib/test/test_asyncio/test_protocols.py
@@ -4,6 +4,12 @@
 import asyncio
 
 
+def tearDownModule():
+    # not needed for the test file but added for uniformness with all other
+    # asyncio test files for the sake of unified cleanup
+    asyncio.set_event_loop_policy(None)
+
+
 class ProtocolsAbsTests(unittest.TestCase):
 
     def test_base_protocol(self):
diff --git a/Lib/test/test_asyncio/test_runners.py b/Lib/test/test_asyncio/test_runners.py
index 5c06a1aaa830f..112273662b20b 100644
--- a/Lib/test/test_asyncio/test_runners.py
+++ b/Lib/test/test_asyncio/test_runners.py
@@ -5,6 +5,10 @@
 from test.test_asyncio import utils as test_utils
 
 
+def tearDownModule():
+    asyncio.set_event_loop_policy(None)
+
+
 class TestPolicy(asyncio.AbstractEventLoopPolicy):
 
     def __init__(self, loop_factory):
diff --git a/Lib/test/test_asyncio/test_sock_lowlevel.py b/Lib/test/test_asyncio/test_sock_lowlevel.py
index 448d835b04d57..14001a4a5001f 100644
--- a/Lib/test/test_asyncio/test_sock_lowlevel.py
+++ b/Lib/test/test_asyncio/test_sock_lowlevel.py
@@ -10,6 +10,10 @@
 from test.support import socket_helper
 
 
+def tearDownModule():
+    asyncio.set_event_loop_policy(None)
+
+
 class MyProto(asyncio.Protocol):
     connected = None
     done = None
diff --git a/Lib/test/test_asyncio/test_transports.py b/Lib/test/test_asyncio/test_transports.py
index df448557a7b7f..bbdb218efaa3b 100644
--- a/Lib/test/test_asyncio/test_transports.py
+++ b/Lib/test/test_asyncio/test_transports.py
@@ -7,6 +7,12 @@
 from asyncio import transports
 
 
+def tearDownModule():
+    # not needed for the test file but added for uniformness with all other
+    # asyncio test files for the sake of unified cleanup
+    asyncio.set_event_loop_policy(None)
+
+
 class TransportTests(unittest.TestCase):
 
     def test_ctor_extra_is_none(self):
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index c3422850ce1b7..2f68459d30cd4 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -26,6 +26,10 @@
 from test.test_asyncio import utils as test_utils
 
 
+def tearDownModule():
+    asyncio.set_event_loop_policy(None)
+
+
 MOCK_ANY = mock.ANY
 
 
@@ -39,10 +43,6 @@ def SIGNAL(signum):
     return 32768 - signum
 
 
-def tearDownModule():
-    asyncio.set_event_loop_policy(None)
-
-
 def close_pipe_transport(transport):
     # Don't call transport.close() because the event loop and the selector
     # are mocked
diff --git a/Misc/NEWS.d/next/Tests/2022-02-10-14-33-47.bpo-46708.avLfCb.rst b/Misc/NEWS.d/next/Tests/2022-02-10-14-33-47.bpo-46708.avLfCb.rst
new file mode 100644
index 0000000000000..119107a8fb96c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-02-10-14-33-47.bpo-46708.avLfCb.rst
@@ -0,0 +1,2 @@
+Prevent default asyncio event loop policy modification warning after
+``test_asyncio`` execution.



More information about the Python-checkins mailing list