forked from cleveragents/cleveragents-core
fix: fix the DeprecationWarning regarding no current event loop in test_bridge.py
This commit is contained in:
@@ -20,8 +20,21 @@ from rx.scheduler.eventloop import AsyncIOScheduler
|
||||
|
||||
@pytest.fixture
|
||||
def scheduler():
|
||||
"""Fixture for AsyncIO scheduler."""
|
||||
return AsyncIOScheduler(loop=asyncio.get_event_loop())
|
||||
"""Fixture for AsyncIO scheduler.
|
||||
|
||||
Note: This fixture works for both sync and async tests. It attempts to use
|
||||
the running event loop (for async test contexts), or creates a new one if
|
||||
needed (for sync test contexts). This avoids the Python 3.12+ deprecation
|
||||
warning for asyncio.get_event_loop() when no loop exists.
|
||||
"""
|
||||
try:
|
||||
# Try to get the running loop (for async test contexts)
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
# No running loop - create a new one for sync tests
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
return AsyncIOScheduler(loop=loop)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user