mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-05-17 10:36:22 +02:00
Fix `There is no current event loop in thread %r` error when running
tests. The `asyncio.get_event_loop` function has been removed in python
3.14.
```
args = (<tests.test_aioclient.AioSimpleWebSocketClientTestCase testMethod=test_close>,), kwargs = {}
def wrapper(*args, **kwargs):
> return _run(coro(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/helpers.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/helpers.py:18: in _run
return asyncio.get_event_loop().run_until_complete(coro)
^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <asyncio.unix_events._UnixDefaultEventLoopPolicy object at 0x7fb66e892900>
def get_event_loop(self):
"""Get the event loop for the current context.
Returns an instance of EventLoop or raises an exception.
"""
if self._local._loop is None:
> raise RuntimeError('There is no current event loop in thread %r.'
% threading.current_thread().name)
E RuntimeError: There is no current event loop in thread 'MainThread'.
/usr/lib/python3.14/asyncio/events.py:715: RuntimeError
```
Ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/18025
13 lines
422 B
Diff
13 lines
422 B
Diff
diff -rupN a/tests/helpers.py b/tests/helpers.py
|
|
--- a/tests/helpers.py 2024-10-10 22:39:23.000000000 +0000
|
|
+++ b/tests/helpers.py 2026-04-02 23:43:30.320000000 +0000
|
|
@@ -15,7 +15,7 @@ def AsyncMock(*args, **kwargs):
|
|
|
|
def _run(coro):
|
|
"""Run the given coroutine."""
|
|
- return asyncio.get_event_loop().run_until_complete(coro)
|
|
+ return asyncio.new_event_loop().run_until_complete(coro)
|
|
|
|
|
|
def make_sync(coro):
|