Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test that asyncio.Runner does not touch the asyncio policy system
  • Loading branch information
graingert committed Jun 22, 2022
commit 7786b44539480337c6832917943229b8a298c3a4
21 changes: 20 additions & 1 deletion Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def set_event_loop(self, loop):
self.loop = loop


class NullPolicy(asyncio.AbstractEventLoopPolicy):

def get_event_loop(self):
# shouldn't ever be called by asyncio.run()
raise RuntimeError

def new_event_loop(self):
raise RuntimeError

def set_event_loop(self, loop):
raise RuntimeError


class BaseTest(unittest.TestCase):

def new_loop(self):
Expand All @@ -60,7 +73,7 @@ async def shutdown_asyncgens():
def setUp(self):
super().setUp()

policy = TestPolicy(self.new_loop)
policy = NullPolicy()
asyncio.set_event_loop_policy(policy)

def tearDown(self):
Expand All @@ -75,6 +88,12 @@ def tearDown(self):

class RunTests(BaseTest):

def setUp(self):
super().setUp()

policy = TestPolicy(self.new_loop)
asyncio.set_event_loop_policy(policy)

def test_asyncio_run_return(self):
async def main():
await asyncio.sleep(0)
Expand Down