Files
MoviePilot/tests/test_main_direct_execution.py
freeman f3ad81b39e style: apply safe ruff auto-fixes and exempt startup late imports
Run `ruff check app tests scripts --fix` with the configured rule set
(E4/E7/E9/F/I): import sorting (I001), f-strings without placeholders
(F541), lambda/variable/unused-import cleanups that ruff marks safe.
Nine files whose only ruff debt sits next to pre-existing pylint
import-resolution errors (lazy exports, sys.path script imports) or
whose "unused" imports are reached through attribute access by tests are
left untouched so the changed-file pylint gate and the benchmark tests
stay green; their diagnostics remain in the baseline.

app/startup/lifecycle/__init__.py and app/main.py import business
modules after cache composition, import-path and stdio setup on purpose
(the source comments document the contract), so declare E402
per-file-ignores for them instead of adding per-line noqa.

Ruff ratchet watermark drops from 498 to 100; sync the baseline fixture
and the optimization checklist figure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-09 13:29:09 +08:00

44 lines
1.3 KiB
Python

import os
import subprocess
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).parents[1]
MAIN_PATH = PROJECT_ROOT / "app" / "main.py"
def test_main_script_does_not_shadow_stdlib_platform(tmp_path):
"""PyCharm 脚本启动路径必须解析到标准库 platform。"""
probe = "\n".join(
(
"import runpy",
"import sys",
# 独立探针不经过 pytest 引导,先隔离站点原生制品,再改变模块搜索路径。
"from app.testing.bootstrap import ensure_sites_stub",
"ensure_sites_stub()",
f"sys.path.insert(0, {str(MAIN_PATH.parent)!r})",
"sys.modules.pop('platform', None)",
f"runpy.run_path({str(MAIN_PATH)!r}, run_name='pycharm_main_probe')",
"import platform",
"assert hasattr(platform, 'python_implementation')",
f"assert {str(MAIN_PATH.parent)!r} not in str(getattr(platform, '__file__', ''))",
)
)
env = {
**os.environ,
"CONFIG_DIR": str(tmp_path / "config"),
"MOVIEPILOT_AUTO_UPDATE": "off",
}
result = subprocess.run(
[sys.executable, "-c", probe],
cwd=PROJECT_ROOT,
env=env,
capture_output=True,
text=True,
timeout=30,
check=False,
)
assert result.returncode == 0, result.stderr