summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorThomas Grainger <tagrain@gmail.com>2023-10-31 22:03:54 (GMT)
committerGitHub <noreply@github.com>2023-10-31 22:03:54 (GMT)
commit770530679e89b06f33655b34a8c466ed906842fe (patch)
treea275b0cff7d2213548eb067bdeb8217dda50490b /Lib/unittest
parentf6a02327b5fcdc10df855985ca9d2d9dc2a0a46f (diff)
downloadcpython-770530679e89b06f33655b34a8c466ed906842fe.zip
cpython-770530679e89b06f33655b34a8c466ed906842fe.tar.gz
cpython-770530679e89b06f33655b34a8c466ed906842fe.tar.bz2
gh-110774: allow setting the Runner(loop_factory=...) from IsolatedAsyncioTestCase (#110776)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl> Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/async_case.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py
index bd2a471..63ff6a5 100644
--- a/Lib/unittest/async_case.py
+++ b/Lib/unittest/async_case.py
@@ -25,12 +25,15 @@ class IsolatedAsyncioTestCase(TestCase):
# them inside the same task.
# Note: the test case modifies event loop policy if the policy was not instantiated
- # yet.
+ # yet, unless loop_factory=asyncio.EventLoop is set.
# asyncio.get_event_loop_policy() creates a default policy on demand but never
# returns None
# I believe this is not an issue in user level tests but python itself for testing
# should reset a policy in every test module
# by calling asyncio.set_event_loop_policy(None) in tearDownModule()
+ # or set loop_factory=asyncio.EventLoop
+
+ loop_factory = None
def __init__(self, methodName='runTest'):
super().__init__(methodName)
@@ -118,7 +121,7 @@ class IsolatedAsyncioTestCase(TestCase):
def _setupAsyncioRunner(self):
assert self._asyncioRunner is None, 'asyncio runner is already initialized'
- runner = asyncio.Runner(debug=True)
+ runner = asyncio.Runner(debug=True, loop_factory=self.loop_factory)
self._asyncioRunner = runner
def _tearDownAsyncioRunner(self):