Skip to content

Commit 012e77e

Browse files
authored
Fix warning: asyncio.events._event_loop_policy was modified by test_asyncio (GH-31253)
1 parent 4f21d52 commit 012e77e

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
from test.test_asyncio import utils as test_utils
2727

2828

29+
def tearDownModule():
30+
asyncio.set_event_loop_policy(None)
31+
32+
2933
MOCK_ANY = mock.ANY
3034

3135

@@ -39,10 +43,6 @@ def SIGNAL(signum):
3943
return 32768 - signum
4044

4145

42-
def tearDownModule():
43-
asyncio.set_event_loop_policy(None)
44-
45-
4646
def close_pipe_transport(transport):
4747
# Don't call transport.close() because the event loop and the selector
4848
# 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)