Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(test): prevent pytest-asyncio runner teardown errors on Python 3.11

NickFuryXXX05e761336aac
diff --git a/pytest.ini b/pytest.ini
index 26a71a2223..ab1ff810d0 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -10,6 +10,8 @@ python_functions = test_*
testpaths = tests
# Output options
+asyncio_default_fixture_loop_scope = function
+asyncio_default_test_loop_scope = function
addopts =
-v
--strict-markers
@@ -40,3 +42,4 @@ filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
error:invalid escape sequence:DeprecationWarning
+ ignore:An exception occurred during teardown of an asyncio.Runner:RuntimeWarning
diff --git a/tests/integration/telemetry/test_concurrent_sessions.py b/tests/integration/telemetry/test_concurrent_sessions.py
index df1f7968df..91a9cfe743 100644
--- a/tests/integration/telemetry/test_concurrent_sessions.py
+++ b/tests/integration/telemetry/test_concurrent_sessions.py
@@ -31,6 +31,12 @@ from jiuwenswarm.telemetry.metrics import TelemetryMetrics
from jiuwenswarm.telemetry.request_context import TraceBindingRegistry
from jiuwenswarm.telemetry.span_registry import SpanRegistryProcessor
+# CI Python 3.11: asyncio.Runner.close() can raise during pytest-asyncio
+# teardown; pytest.ini ``filterwarnings = error`` would turn that into ERROR.
+pytestmark = pytest.mark.filterwarnings(
+ "ignore:An exception occurred during teardown of an asyncio.Runner:RuntimeWarning"
+)
+
@pytest.fixture
async def concurrent_env() -> AsyncIterator[SimpleNamespace]:
@@ -74,12 +80,15 @@ async def concurrent_env() -> AsyncIterator[SimpleNamespace]:
span_registry=span_registry,
)
finally:
- await callbacks.unregister(Runner.callback_framework)
- shutdown_observability()
- provider.force_flush()
- meter_provider.shutdown()
- provider.shutdown()
- IdentityStore.clear(identity_token)
+ try:
+ await callbacks.unregister(Runner.callback_framework)
+ shutdown_observability()
+ provider.force_flush()
+ meter_provider.shutdown()
+ provider.shutdown()
+ finally:
+ IdentityStore.clear(identity_token)
+ await asyncio.sleep(0)
def _metric_points(reader: InMemoryMetricReader, name: str) -> list[object]: