Skip to content

Your lightweight open-source personal agent.

test: speed up test suite

chengyongru4378944459e9
diff --git a/nanobot/channels/email.py b/nanobot/channels/email.py
index 7d1abf244..a74764516 100644
--- a/nanobot/channels/email.py
+++ b/nanobot/channels/email.py
@@ -199,6 +199,8 @@ class EmailChannel(BaseChannel):
except Exception:
self.logger.exception("Polling error")
+ if not self._running:
+ break
await asyncio.sleep(poll_seconds)
async def stop(self) -> None:
diff --git a/tests/channels/test_feishu_lazy_import.py b/tests/channels/test_feishu_lazy_import.py
index d43c39ebb..05915c275 100644
--- a/tests/channels/test_feishu_lazy_import.py
+++ b/tests/channels/test_feishu_lazy_import.py
@@ -35,7 +35,20 @@ def test_feishu_channel_constructor_does_not_import_lark_oapi():
def test_lark_runtime_thread_import_clears_sdk_import_loop():
out = _run_import_probe(
"import asyncio\n"
+ "import sys\n"
+ "import tempfile\n"
+ "from pathlib import Path\n"
"from nanobot.channels.feishu import _load_lark_runtime\n"
+ "root = Path(tempfile.mkdtemp())\n"
+ "pkg = root / 'lark_oapi'\n"
+ "(pkg / 'ws').mkdir(parents=True)\n"
+ "(pkg / 'core').mkdir(parents=True)\n"
+ "(pkg / '__init__.py').write_text('class LogLevel:\\n INFO = 20\\n')\n"
+ "(pkg / 'ws' / '__init__.py').write_text('')\n"
+ "(pkg / 'ws' / 'client.py').write_text('import asyncio\\nloop = asyncio.new_event_loop()\\n')\n"
+ "(pkg / 'core' / '__init__.py').write_text('')\n"
+ "(pkg / 'core' / 'const.py').write_text(\"FEISHU_DOMAIN = 'feishu'\\nLARK_DOMAIN = 'lark'\\n\")\n"
+ "sys.path.insert(0, str(root))\n"
"async def main():\n"
" await asyncio.to_thread(_load_lark_runtime)\n"
" import lark_oapi.ws.client as ws\n"
diff --git a/tests/channels/test_websocket_channel.py b/tests/channels/test_websocket_channel.py
index 9ca0a3340..2d8e92a2d 100644
--- a/tests/channels/test_websocket_channel.py
+++ b/tests/channels/test_websocket_channel.py
@@ -136,7 +136,7 @@ def isolate_webui_workspace_state(tmp_path, monkeypatch) -> None:
async def _http_get(url: str, headers: dict[str, str] | None = None) -> httpx.Response:
"""Run GET in a thread to avoid blocking the asyncio loop shared with websockets."""
return await asyncio.to_thread(
- functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0)
+ functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0, trust_env=False)
)
diff --git a/tests/channels/test_websocket_http_routes.py b/tests/channels/test_websocket_http_routes.py
index 166740929..d767b6f1c 100644
--- a/tests/channels/test_websocket_http_routes.py
+++ b/tests/channels/test_websocket_http_routes.py
@@ -109,7 +109,7 @@ async def _http_get(
url: str, headers: dict[str, str] | None = None
) -> httpx.Response:
return await asyncio.to_thread(
- functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0)
+ functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0, trust_env=False)
)
@@ -506,12 +506,11 @@ async def test_cli_apps_catalog_does_not_block_other_webui_http_routes(
token = boot.json()["token"]
auth = {"Authorization": f"Bearer {token}"}
- started = time.perf_counter()
catalog_task = asyncio.create_task(
_http_get("http://127.0.0.1:29935/api/settings/cli-apps", headers=auth)
)
assert await asyncio.wait_for(entered.wait(), 2.0)
- assert time.perf_counter() - started < 1.0
+ assert not catalog_task.done()
workspaces_started = time.perf_counter()
workspaces = await _http_get("http://127.0.0.1:29935/api/workspaces", headers=auth)
diff --git a/tests/channels/test_websocket_media_route.py b/tests/channels/test_websocket_media_route.py
index d539dd914..0b8b7cd63 100644
--- a/tests/channels/test_websocket_media_route.py
+++ b/tests/channels/test_websocket_media_route.py
@@ -90,7 +90,7 @@ async def _http_get(
url: str, headers: dict[str, str] | None = None
) -> httpx.Response:
return await asyncio.to_thread(
- functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0)
+ functools.partial(httpx.get, url, headers=headers or {}, timeout=5.0, trust_env=False)
)
diff --git a/tests/providers/test_litellm_kwargs.py b/tests/providers/test_litellm_kwargs.py
index 872e1b512..61577c40e 100644
--- a/tests/providers/test_litellm_kwargs.py
+++ b/tests/providers/test_litellm_kwargs.py
@@ -1228,7 +1228,7 @@ def test_openai_compat_defaults_missing_tool_arguments_to_empty_object() -> None
@pytest.mark.asyncio
async def test_openai_compat_stream_watchdog_returns_error_on_stall(monkeypatch) -> None:
- monkeypatch.setenv("NANOBOT_STREAM_IDLE_TIMEOUT_S", "0")
+ monkeypatch.setenv("NANOBOT_STREAM_IDLE_TIMEOUT_S", "0.01")
mock_create = AsyncMock(return_value=_StalledStream())
spec = find_by_name("openai")