From f88e0222297025f02f938cc010d1801d935bbcbc Mon Sep 17 00:00:00 2001 From: claude-ceo-assistant Date: Fri, 8 May 2026 03:46:57 +0000 Subject: [PATCH] test(teams): patch adapter's TypingActivityInput binding for test_send_typing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The teams adapter imports TypingActivityInput at module load time: try: from microsoft_teams.api.activities.typing import TypingActivityInput except ImportError: TypingActivityInput = None When the real microsoft_teams package isn't installed (CI runner image doesn't bundle Microsoft Teams SDK), the import fails and the local binding stays None — even though the test file's _ensure_teams_mock fixture registers a MockTypingActivityInput in sys.modules. The test-time mock-in-sys.modules trick only fixes future imports; a binding captured before the mock was registered remains stale. send_typing() calls TypingActivityInput() and the resulting TypeError ('NoneType' object is not callable) is swallowed by `except Exception: pass`, so self._app.send is never reached and the test's assert_awaited_once fails with "Awaited 0 times" — invisibly, because the swallowed error hid the real cause. Fix: monkey-patch the adapter module's local TypingActivityInput binding in test_send_typing only — narrowest possible patch since no other test exercises send_typing. Document the import-time-vs-mock-time gap inline so a future reader doesn't fall into the same trap. Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/gateway/test_teams.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/gateway/test_teams.py b/tests/gateway/test_teams.py index 7a035142..2100a264 100644 --- a/tests/gateway/test_teams.py +++ b/tests/gateway/test_teams.py @@ -397,13 +397,22 @@ class TestTeamsSend: assert "Network error" in result.error @pytest.mark.asyncio - async def test_send_typing(self): + async def test_send_typing(self, monkeypatch): adapter = TeamsAdapter(_make_config( client_id="id", client_secret="secret", tenant_id="tenant", )) mock_app = MagicMock() mock_app.send = AsyncMock() adapter._app = mock_app + # The adapter module imports TypingActivityInput at load time; if + # the real microsoft_teams package isn'"'"'t installed, that local + # binding is None even though the test fixture registers a mock + # in sys.modules. Force a non-None local binding so the call to + # TypingActivityInput() inside send_typing succeeds and we actually + # reach self._app.send. + class _StubTypingActivityInput: + pass + monkeypatch.setattr(_teams_mod, "TypingActivityInput", _StubTypingActivityInput) await adapter.send_typing("conv-id") mock_app.send.assert_awaited_once()