From 8d9babe52eabf7488e6fc06d4223e20d36ffd3f4 Mon Sep 17 00:00:00 2001 From: Adam Moussa Date: Thu, 18 Jun 2026 13:00:34 -0400 Subject: [PATCH] test(agent-team): make slack_live token test independent of slack_sdk presence CI lacks slack_sdk, so the deferred-import-missing error fired before the no-token check and masked it. Stub slack_sdk into sys.modules so the token branch is deterministically exercised in both environments. --- agent-team/tests/test_slack_live.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/agent-team/tests/test_slack_live.py b/agent-team/tests/test_slack_live.py index 48dfdf1..6d3fbf8 100644 --- a/agent-team/tests/test_slack_live.py +++ b/agent-team/tests/test_slack_live.py @@ -214,7 +214,19 @@ def test_poster_unsupported_response_raises_type_error() -> None: def test_missing_token_raises_runtime_error(monkeypatch: pytest.MonkeyPatch) -> None: - """No token and no SLACK_BOT_TOKEN raises a clear RuntimeError.""" + """No token and no SLACK_BOT_TOKEN raises a clear RuntimeError. + + Stub ``slack_sdk`` into ``sys.modules`` so the deferred import SUCCEEDS and + the no-token branch is what's under test. Without this the test is + environment-dependent: where slack_sdk is absent (CI) the import-missing + error fires first and masks the token check (local-vs-CI drift). + """ + import sys + from types import ModuleType + + fake = ModuleType("slack_sdk") + fake.WebClient = lambda **kw: None # type: ignore[attr-defined] + monkeypatch.setitem(sys.modules, "slack_sdk", fake) monkeypatch.delenv("SLACK_BOT_TOKEN", raising=False) with pytest.raises(RuntimeError, match="Slack bot token"):