fix: fix the DeprecationWarning regarding no current event loop in test_bridge.py

This commit is contained in:
2025-11-13 19:50:09 +05:30
parent 485084fbcc
commit b8efe9343d
+15 -2
View File
@@ -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