fix(skills): green telegram skill tests (telethon stub) + pyright pytest resolution
- telegram skill: register a minimal telethon sys.modules stub in the test conftest so botfather_client tests (which patch telethon.*) run without the optional MTProto library installed. Fixes 7 ModuleNotFoundError failures; telegram suite now 452/452 green. - pyrightconfig.json: add the root .venv site-packages to extraPaths (has pytest + project deps) alongside memory's venv, so the @hooks auto_fix pyright check stops emitting false 'Import pytest could not be resolved' on every test file. CI does not run pyright; this is local-DX only. Both CI-safe: telegram tests live under .aipass/ (excluded from umbrella pytest) and pyright is not a CI gate, so PR #640 stays green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
8ad4de11eb
commit
c8ae084f54
+5
-1
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"extraPaths": ["src", "src/aipass/memory/.venv/lib/python3.12/site-packages"],
|
||||
"extraPaths": [
|
||||
"src",
|
||||
".venv/lib/python3.12/site-packages",
|
||||
"src/aipass/memory/.venv/lib/python3.12/site-packages"
|
||||
],
|
||||
"pythonVersion": "3.10",
|
||||
"reportMissingImports": "error",
|
||||
"reportAttributeAccessIssue": "error",
|
||||
|
||||
@@ -18,6 +18,7 @@ import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import types
|
||||
from pathlib import Path
|
||||
from typing import Generator
|
||||
|
||||
@@ -37,6 +38,38 @@ if str(_skill_root) not in sys.path:
|
||||
sys.path.insert(0, str(_skill_root))
|
||||
|
||||
|
||||
# Telethon stub — telethon is an OPTIONAL runtime dependency (MTProto client),
|
||||
# deliberately NOT in pyproject so the core stays lightweight (botfather_client.py
|
||||
# guards it with TELETHON_AVAILABLE). The botfather_client tests mock all Telethon
|
||||
# classes (patch("telethon.TelegramClient"), etc.), but unittest.mock.patch must
|
||||
# IMPORT the target's parent module to set the attribute — which raises
|
||||
# ModuleNotFoundError when telethon isn't installed (e.g. in CI). Register a minimal
|
||||
# stub so those patch targets resolve. The guard never clobbers a real telethon if
|
||||
# one is installed. Real FloodWaitError/RPCError classes are required for the
|
||||
# success/timeout tests, where _send_and_wait imports them but does not patch them.
|
||||
if "telethon" not in sys.modules:
|
||||
_telethon_stub = types.ModuleType("telethon")
|
||||
_telethon_errors = types.ModuleType("telethon.errors")
|
||||
|
||||
class StubFloodWaitError(Exception):
|
||||
def __init__(self, *args: object, seconds: int = 0, **kwargs: object) -> None:
|
||||
self.seconds = seconds
|
||||
super().__init__(*args)
|
||||
|
||||
class StubRPCError(Exception):
|
||||
pass
|
||||
|
||||
# ModuleType attributes are dynamic — assign via setattr so the type checker
|
||||
# does not flag assignment to "unknown" module attributes.
|
||||
setattr(_telethon_stub, "TelegramClient", type("TelegramClient", (), {})) # patched per-test
|
||||
setattr(_telethon_errors, "FloodWaitError", StubFloodWaitError)
|
||||
setattr(_telethon_errors, "RPCError", StubRPCError)
|
||||
setattr(_telethon_stub, "errors", _telethon_errors)
|
||||
|
||||
sys.modules["telethon"] = _telethon_stub
|
||||
sys.modules["telethon.errors"] = _telethon_errors
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def _redirect_prax_logs(tmp_path_factory):
|
||||
"""Redirect Prax logger output to temp dir during tests.
|
||||
|
||||
Reference in New Issue
Block a user