aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_events.py
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-12-24 19:24:28 +0530
committerGitHub <noreply@github.com>2024-12-24 19:24:28 +0530
commit9fce90682553e2cfe93e98e2ae5948bf9c7c4456 (patch)
tree68349cd7bec642cadc1bb7436d1f0c54ccb91366 /Lib/test/test_asyncio/test_events.py
parent3ddd70ceaaf67b111ee4251817e150396d6d10a9 (diff)
downloadcpython-9fce90682553e2cfe93e98e2ae5948bf9c7c4456.tar.gz
cpython-9fce90682553e2cfe93e98e2ae5948bf9c7c4456.zip
gh-127949: deprecate `asyncio.set_event_loop` (#128218)
Deprecate `asyncio.set_event_loop` to be removed in Python 3.16.
Diffstat (limited to 'Lib/test/test_asyncio/test_events.py')
-rw-r--r--Lib/test/test_asyncio/test_events.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index c626670f72a..c8439c9af5e 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -58,7 +58,7 @@ def _test_get_event_loop_new_process__sub_proc():
return 'hello'
loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
+ asyncio._set_event_loop(loop)
return loop.run_until_complete(doit())
@@ -2695,6 +2695,14 @@ class AbstractEventLoopTests(unittest.TestCase):
class PolicyTests(unittest.TestCase):
+ def test_asyncio_set_event_loop_deprecation(self):
+ with self.assertWarnsRegex(
+ DeprecationWarning, "'asyncio.set_event_loop' is deprecated"):
+ loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(loop)
+ self.assertIs(loop, asyncio.get_event_loop())
+ loop.close()
+
def test_abstract_event_loop_policy_deprecation(self):
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.AbstractEventLoopPolicy' is deprecated"):
@@ -2824,14 +2832,14 @@ class GetEventLoopTestsMixin:
super().setUp()
self.loop = asyncio.new_event_loop()
- asyncio.set_event_loop(self.loop)
+ asyncio._set_event_loop(self.loop)
def tearDown(self):
try:
super().tearDown()
finally:
self.loop.close()
- asyncio.set_event_loop(None)
+ asyncio._set_event_loop(None)
events._get_running_loop = self._get_running_loop_saved
events._set_running_loop = self._set_running_loop_saved
@@ -2885,7 +2893,7 @@ class GetEventLoopTestsMixin:
with self.assertRaises(TestError):
asyncio.get_event_loop()
- asyncio.set_event_loop(None)
+ asyncio._set_event_loop(None)
with self.assertRaises(TestError):
asyncio.get_event_loop()
@@ -2900,10 +2908,10 @@ class GetEventLoopTestsMixin:
loop.run_until_complete(func())
- asyncio.set_event_loop(loop)
+ asyncio._set_event_loop(loop)
with self.assertRaises(TestError):
asyncio.get_event_loop()
- asyncio.set_event_loop(None)
+ asyncio._set_event_loop(None)
with self.assertRaises(TestError):
asyncio.get_event_loop()
@@ -2927,7 +2935,7 @@ class GetEventLoopTestsMixin:
with self.assertRaisesRegex(RuntimeError, 'no current'):
asyncio.get_event_loop()
- asyncio.set_event_loop(None)
+ asyncio._set_event_loop(None)
with self.assertRaisesRegex(RuntimeError, 'no current'):
asyncio.get_event_loop()
@@ -2938,10 +2946,10 @@ class GetEventLoopTestsMixin:
loop.run_until_complete(func())
- asyncio.set_event_loop(loop)
+ asyncio._set_event_loop(loop)
self.assertIs(asyncio.get_event_loop(), loop)
- asyncio.set_event_loop(None)
+ asyncio._set_event_loop(None)
with self.assertRaisesRegex(RuntimeError, 'no current'):
asyncio.get_event_loop()