Skip to content

Commit a65be6e

Browse files
authored
[3.9] Fix warning: asyncio.events._event_loop_policy was modified by test_asyncio (GH-31253). (GH-31256)
(cherry picked from commit 012e77e) Co-authored-by: Andrew Svetlov <[email protected]>
1 parent b0517a1 commit a65be6e

File tree

7 files changed

+29
-3
lines changed

7 files changed

+29
-3
lines changed

Lib/test/test_asyncio/test_futures2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import unittest
44

55

6+
def tearDownModule():
7+
asyncio.set_event_loop_policy(None)
8+
9+
610
class FutureTests(unittest.IsolatedAsyncioTestCase):
711
async def test_recursive_repr_for_pending_tasks(self):
812
# The call crashes if the guard for recursive call

Lib/test/test_asyncio/test_protocols.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
import asyncio
55

66

7+
def tearDownModule():
8+
# not needed for the test file but added for uniformness with all other
9+
# asyncio test files for the sake of unified cleanup
10+
asyncio.set_event_loop_policy(None)
11+
12+
713
class ProtocolsAbsTests(unittest.TestCase):
814

915
def test_base_protocol(self):

Lib/test/test_asyncio/test_runners.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from test.test_asyncio import utils as test_utils
66

77

8+
def tearDownModule():
9+
asyncio.set_event_loop_policy(None)
10+
11+
812
class TestPolicy(asyncio.AbstractEventLoopPolicy):
913

1014
def __init__(self, loop_factory):

Lib/test/test_asyncio/test_sock_lowlevel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from test.support import socket_helper
1111

1212

13+
def tearDownModule():
14+
asyncio.set_event_loop_policy(None)
15+
16+
1317
class MyProto(asyncio.Protocol):
1418
connected = None
1519
done = None

Lib/test/test_asyncio/test_transports.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
from asyncio import transports
88

99

10+
def tearDownModule():
11+
# not needed for the test file but added for uniformness with all other
12+
# asyncio test files for the sake of unified cleanup
13+
asyncio.set_event_loop_policy(None)
14+
15+
1016
class TransportTests(unittest.TestCase):
1117

1218
def test_ctor_extra_is_none(self):

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
from test.test_asyncio import utils as test_utils
2828

2929

30-
MOCK_ANY = mock.ANY
31-
32-
3330
def tearDownModule():
3431
asyncio.set_event_loop_policy(None)
3532

3633

34+
MOCK_ANY = mock.ANY
35+
36+
3737
def close_pipe_transport(transport):
3838
# Don't call transport.close() because the event loop and the selector
3939
# are mocked
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent default asyncio event loop policy modification warning after
2+
``test_asyncio`` execution.

0 commit comments

Comments
 (0)