Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f7a1b68

Browse files
committedOct 11, 2023
add support.set_event_loop_policy for setting the event loop policy in tests
1 parent 43cbdb2 commit f7a1b68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+92
-64
lines changed
 

‎Lib/test/libregrtest/save_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_asyncio_events__event_loop_policy(self):
9797
return support.maybe_get_event_loop_policy()
9898
def restore_asyncio_events__event_loop_policy(self, policy):
9999
asyncio = self.get_module('asyncio')
100-
asyncio.set_event_loop_policy(policy)
100+
support.set_event_loop_policy(policy)
101101

102102
def get_sys_argv(self):
103103
return id(sys.argv), sys.argv, sys.argv[:]

‎Lib/test/support/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,13 @@ def maybe_get_event_loop_policy():
20892089
import asyncio.events
20902090
return asyncio.events._event_loop_policy
20912091

2092+
def set_event_loop_policy(policy):
2093+
"""Set the global event loop policy ignoring deprecation warnings"""
2094+
import asyncio
2095+
with warnings.catch_warnings():
2096+
warnings.simplefilter("ignore", DeprecationWarning)
2097+
asyncio.set_event_loop_policy(policy)
2098+
20922099
# Helpers for testing hashing.
20932100
NHASHBITS = sys.hash_info.width # number of bits in hash() result
20942101
assert NHASHBITS in (32, 64)

0 commit comments

Comments
 (0)
Please sign in to comment.