refactor: remove 19 duplicate _ensure_telegram_mock() copies from gateway tests - #91401
Merged
kshitijk4poor merged 1 commit intoAug 21, 2026
Merged
Conversation
kshitijk4poor
force-pushed
the
refactor/dedupe-telegram-mock
branch
from
August 21, 2026 10:50
5a7c574 to
a9d18db
Compare
kshitijk4poor
enabled auto-merge
August 21, 2026 10:50
…eway tests tests/gateway/conftest.py already installs a comprehensive telegram mock at collection time (line 330), before any test module's imports run. The per-file copies were fully redundant — each was a simpler subset (plain strings, setdefault, fewer error classes) of the conftest version (which uses _fake_str_enum for PTB-faithful StrEnum semantics, sys.modules overwrite to win over partial/broken imports, and a full error hierarchy including BadRequest, Forbidden, RetryAfter, Conflict, InvalidToken). Removed: function def + module-level call + now-unused imports (sys, MagicMock where no longer referenced) + dangling comment blocks that referenced the deleted mock, in 27 test files. Left untouched: tests/gateway/conftest.py (canonical source) and tests/e2e/conftest.py (separate conftest tree that may run in isolation). Found by /simplify-code review of PR NousResearch#90560.
kshitijk4poor
force-pushed
the
refactor/dedupe-telegram-mock
branch
from
August 21, 2026 10:55
a9d18db to
c1693d7
Compare
melon-xf
added a commit
to melon-xf/hermes-agent
that referenced
this pull request
Sep 3, 2026
…upe-telegram-mock refactor: remove 19 duplicate _ensure_telegram_mock() copies from gateway tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removed 27 redundant
_ensure_telegram_mock()copies from gateway test files — the comprehensive version intests/gateway/conftest.py(installed at collection time, line 330) already covers all of them.Changes
_ensure_telegram_mock()function def + module-level call + now-unused imports (sys,MagicMockwhere no longer referenced) + dangling comment blocks that referenced the deleted mocktests/gateway/conftest.py(canonical source) andtests/e2e/conftest.py(separate conftest tree)The conftest version is strictly superior to every per-file copy:
_fake_str_enumfor PTB-faithfulStrEnumsemantics (plain strings breakrepr()assertions)sys.modules[name] = mod(overwrite) instead ofsetdefault(wins over partial/broken imports)TelegramError,NetworkError,TimedOut,BadRequest,Forbidden,InvalidToken,RetryAfter,ConflictUpdate.ALL_TYPESused instart_polling()Per-file copies were simpler subsets (plain strings,
setdefault, fewer error classes) that could drift independently —test_telegram_voice_duration.pyalready had a variant that omittedChatType/ContextTypes/ParseMode.Validation
_ensure_telegram_mockFound by /simplify-code review of PR #90560. Expanded from initial 19 to 27 files after /simplify-code Phase 2 on this PR found 8 more copies.