async def main():
# asyncio.Runner did not call asyncio.set_event_loop()
- with self.assertRaises(RuntimeError):
- asyncio.get_event_loop_policy().get_event_loop()
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', DeprecationWarning)
+ # get_event_loop() raises DeprecationWarning if
+ # set_event_loop() was never called and RuntimeError if
+ # it was called at least once.
+ with self.assertRaises((RuntimeError, DeprecationWarning)):
+ asyncio.get_event_loop_policy().get_event_loop()
return await asyncio.to_thread(asyncio.run, in_thread())
with self.assertWarns(DeprecationWarning):
asyncio.set_child_watcher(asyncio.PidfdChildWatcher())