Skip to content

Commit f9ad986

Browse files
committed
fix(tests): isolate ALLOWED_CHAT_IDS state in test_chat_allowlist to prevent test suite pollution (chigwell#212)
1 parent 114b7d8 commit f9ad986

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎tests/test_chat_allowlist.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
from telegram_mcp.tools import chats, messages
2424

2525

26+
@pytest.fixture(autouse=True)
27+
def _reset_chat_allowlist_global_state(monkeypatch):
28+
monkeypatch.delenv("TELEGRAM_ALLOWED_CHAT_IDS", raising=False)
29+
monkeypatch.setattr(runtime, "ALLOWED_CHAT_IDS", None)
30+
if hasattr(main, "ALLOWED_CHAT_IDS"):
31+
monkeypatch.setattr(main, "ALLOWED_CHAT_IDS", None)
32+
yield
33+
monkeypatch.delenv("TELEGRAM_ALLOWED_CHAT_IDS", raising=False)
34+
monkeypatch.setattr(runtime, "ALLOWED_CHAT_IDS", None)
35+
if hasattr(main, "ALLOWED_CHAT_IDS"):
36+
monkeypatch.setattr(main, "ALLOWED_CHAT_IDS", None)
37+
38+
2639
class FakeDialog:
2740
def __init__(self, entity, unread_count=0, archived=False):
2841
self.entity = entity
@@ -357,6 +370,7 @@ async def test_create_poll_blocks_unallowed_chat(monkeypatch):
357370
def test_main_compatibility_aliases(monkeypatch):
358371
monkeypatch.delenv("TELEGRAM_ALLOWED_CHAT_IDS", raising=False)
359372
monkeypatch.setattr(main, "ALLOWED_CHAT_IDS", None)
373+
monkeypatch.setattr(runtime, "ALLOWED_CHAT_IDS", None)
360374

361375
assert not main.is_chat_allowlist_enabled()
362376

0 commit comments

Comments
 (0)