@@ -58,7 +58,7 @@ async def doit():
5858 return 'hello'
5959
6060 loop = asyncio .new_event_loop ()
61- asyncio .set_event_loop (loop )
61+ asyncio ._set_event_loop (loop )
6262 return loop .run_until_complete (doit ())
6363
6464
@@ -2695,6 +2695,14 @@ async def inner():
26952695
26962696class PolicyTests (unittest .TestCase ):
26972697
2698+ def test_asyncio_set_event_loop_deprecation (self ):
2699+ with self .assertWarnsRegex (
2700+ DeprecationWarning , "'asyncio.set_event_loop' is deprecated" ):
2701+ loop = asyncio .new_event_loop ()
2702+ asyncio .set_event_loop (loop )
2703+ self .assertIs (loop , asyncio .get_event_loop ())
2704+ loop .close ()
2705+
26982706 def test_abstract_event_loop_policy_deprecation (self ):
26992707 with self .assertWarnsRegex (
27002708 DeprecationWarning , "'asyncio.AbstractEventLoopPolicy' is deprecated" ):
@@ -2824,14 +2832,14 @@ def setUp(self):
28242832 super ().setUp ()
28252833
28262834 self .loop = asyncio .new_event_loop ()
2827- asyncio .set_event_loop (self .loop )
2835+ asyncio ._set_event_loop (self .loop )
28282836
28292837 def tearDown (self ):
28302838 try :
28312839 super ().tearDown ()
28322840 finally :
28332841 self .loop .close ()
2834- asyncio .set_event_loop (None )
2842+ asyncio ._set_event_loop (None )
28352843
28362844 events ._get_running_loop = self ._get_running_loop_saved
28372845 events ._set_running_loop = self ._set_running_loop_saved
@@ -2885,7 +2893,7 @@ def get_event_loop(self):
28852893
28862894 with self .assertRaises (TestError ):
28872895 asyncio .get_event_loop ()
2888- asyncio .set_event_loop (None )
2896+ asyncio ._set_event_loop (None )
28892897 with self .assertRaises (TestError ):
28902898 asyncio .get_event_loop ()
28912899
@@ -2900,10 +2908,10 @@ async def func():
29002908
29012909 loop .run_until_complete (func ())
29022910
2903- asyncio .set_event_loop (loop )
2911+ asyncio ._set_event_loop (loop )
29042912 with self .assertRaises (TestError ):
29052913 asyncio .get_event_loop ()
2906- asyncio .set_event_loop (None )
2914+ asyncio ._set_event_loop (None )
29072915 with self .assertRaises (TestError ):
29082916 asyncio .get_event_loop ()
29092917
@@ -2927,7 +2935,7 @@ def test_get_event_loop_returns_running_loop2(self):
29272935 with self .assertRaisesRegex (RuntimeError , 'no current' ):
29282936 asyncio .get_event_loop ()
29292937
2930- asyncio .set_event_loop (None )
2938+ asyncio ._set_event_loop (None )
29312939 with self .assertRaisesRegex (RuntimeError , 'no current' ):
29322940 asyncio .get_event_loop ()
29332941
@@ -2938,10 +2946,10 @@ async def func():
29382946
29392947 loop .run_until_complete (func ())
29402948
2941- asyncio .set_event_loop (loop )
2949+ asyncio ._set_event_loop (loop )
29422950 self .assertIs (asyncio .get_event_loop (), loop )
29432951
2944- asyncio .set_event_loop (None )
2952+ asyncio ._set_event_loop (None )
29452953 with self .assertRaisesRegex (RuntimeError , 'no current' ):
29462954 asyncio .get_event_loop ()
29472955
0 commit comments