The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: bind lark SDK globals session-wide, not per-file
kshitijk4poorf84e3687d873
diff --git a/tests/gateway/conftest.py b/tests/gateway/conftest.pyindex 7a21465dd3d..d485d4ab2fe 100644--- a/tests/gateway/conftest.py+++ b/tests/gateway/conftest.py@@ -39,6 +39,33 @@ from unittest.mock import MagicMockimport pytest[email protected](scope="session", autouse=True)+def _bind_lark_sdk_globals_when_installed():+ """Bind the feishu adapter's lark SDK globals once per test session.++ The adapter defers ``import lark_oapi`` to first use+ (``_load_lark_oapi`` — called from connect()/probe_bot()/standalone+ send), so the request-builder globals (``CreateMessageRequestBody``+ etc.) stay ``None`` at module import time. Feishu tests across many+ files inject a mock ``_client`` and skip connect() entirely, then call+ send paths that reference those globals. Bind them eagerly when the+ SDK is installed; when it isn't, the affected tests already skip via+ their own ``skipUnless`` guards.+ """+ try:+ import lark_oapi # noqa: F401+ except ImportError:+ yield+ return+ try:+ from plugins.platforms.feishu.adapter import _load_lark_oapi++ _load_lark_oapi()+ except Exception:+ pass # adapter not importable in this environment — tests will skip+ yield++def make_async_session_db(sync_mock=None):"""Wrap a sync mock SessionDB in AsyncSessionDB so gateway code that awaitsthe facade works in tests. Returns (facade, sync_mock); configure returndiff --git a/tests/gateway/test_feishu.py b/tests/gateway/test_feishu.pyindex 0d861812c5a..a923ea5f5d4 100644--- a/tests/gateway/test_feishu.py+++ b/tests/gateway/test_feishu.py@@ -22,18 +22,6 @@ except ImportError:_HAS_LARK_OAPI = False-def setUpModule():- """Bind the lark SDK globals before tests that inject a mock ``_client``.-- The adapter defers the lark import to ``connect()`` (``_load_lark_oapi``),- so tests that skip connect() and set ``adapter._client`` directly would- otherwise see the request-builder globals still bound to None.- """- if _HAS_LARK_OAPI:- from plugins.platforms.feishu.adapter import _load_lark_oapi- _load_lark_oapi()--class _FakeRequestContent:def __init__(self, body: bytes):self.body = body