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.
This commit is contained in:
parent
0f33fa6f24
commit
8d9babe52e
1 changed files with 13 additions and 1 deletions
|
|
@ -214,7 +214,19 @@ def test_poster_unsupported_response_raises_type_error() -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_missing_token_raises_runtime_error(monkeypatch: pytest.MonkeyPatch) -> 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)
|
monkeypatch.delenv("SLACK_BOT_TOKEN", raising=False)
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="Slack bot token"):
|
with pytest.raises(RuntimeError, match="Slack bot token"):
|
||||||
|
|
|
||||||
Reference in a new issue