mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-14 04:02:26 +00:00
fix(tests): avoid asyncio DeprecationWarning in event loop fixture on 3.12+
This commit is contained in:
parent
12a0f5901c
commit
d5fcc83922
1 changed files with 13 additions and 2 deletions
|
|
@ -483,15 +483,26 @@ def _ensure_current_event_loop(request):
|
||||||
A number of gateway tests still use asyncio.get_event_loop().run_until_complete(...).
|
A number of gateway tests still use asyncio.get_event_loop().run_until_complete(...).
|
||||||
Ensure they always have a usable loop without interfering with pytest-asyncio's
|
Ensure they always have a usable loop without interfering with pytest-asyncio's
|
||||||
own loop management for @pytest.mark.asyncio tests.
|
own loop management for @pytest.mark.asyncio tests.
|
||||||
|
|
||||||
|
On Python 3.12+, ``asyncio.get_event_loop_policy().get_event_loop()`` with no
|
||||||
|
*running* loop emits DeprecationWarning; skip that path and install a fresh
|
||||||
|
loop via ``new_event_loop()`` instead.
|
||||||
"""
|
"""
|
||||||
if request.node.get_closest_marker("asyncio") is not None:
|
if request.node.get_closest_marker("asyncio") is not None:
|
||||||
yield
|
yield
|
||||||
return
|
return
|
||||||
|
|
||||||
|
loop = None
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop_policy().get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
loop = None
|
pass
|
||||||
|
|
||||||
|
if loop is None and sys.version_info < (3, 12):
|
||||||
|
try:
|
||||||
|
loop = asyncio.get_event_loop_policy().get_event_loop()
|
||||||
|
except RuntimeError:
|
||||||
|
loop = None
|
||||||
|
|
||||||
created = loop is None or loop.is_closed()
|
created = loop is None or loop.is_closed()
|
||||||
if created:
|
if created:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue