Skip to content

Commit 7786b44

Browse files
committed
test that asyncio.Runner does not touch the asyncio policy system
1 parent 428cc8a commit 7786b44

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Lib/test/test_asyncio/test_runners.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ def set_event_loop(self, loop):
3939
self.loop = loop
4040

4141

42+
class NullPolicy(asyncio.AbstractEventLoopPolicy):
43+
44+
def get_event_loop(self):
45+
# shouldn't ever be called by asyncio.run()
46+
raise RuntimeError
47+
48+
def new_event_loop(self):
49+
raise RuntimeError
50+
51+
def set_event_loop(self, loop):
52+
raise RuntimeError
53+
54+
4255
class BaseTest(unittest.TestCase):
4356

4457
def new_loop(self):
@@ -60,7 +73,7 @@ async def shutdown_asyncgens():
6073
def setUp(self):
6174
super().setUp()
6275

63-
policy = TestPolicy(self.new_loop)
76+
policy = NullPolicy()
6477
asyncio.set_event_loop_policy(policy)
6578

6679
def tearDown(self):
@@ -75,6 +88,12 @@ def tearDown(self):
7588

7689
class RunTests(BaseTest):
7790

91+
def setUp(self):
92+
super().setUp()
93+
94+
policy = TestPolicy(self.new_loop)
95+
asyncio.set_event_loop_policy(policy)
96+
7897
def test_asyncio_run_return(self):
7998
async def main():
8099
await asyncio.sleep(0)

0 commit comments

Comments
 (0)