mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix(test): 修复 doctor/monitor 惰性门面用例在无站点资源的 CI 子进程中失败
该用例以独立子进程加载 app.monitor 实现,链路最终 import app.application.site.sites;CI 无该动态资源模块且子进程不经过 conftest 引导,导致 ModuleNotFoundError。改为触发实现加载前显式 安装与 conftest 同源的 sites 垫片,并通过 CONFIG_DIR 指向临时 目录隔离子进程配置。
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -166,7 +167,7 @@ assert sanitize_for_host({'token': 'secret'}) == {'token': '***'}
|
|||||||
assert result.returncode == 0, result.stderr
|
assert result.returncode == 0, result.stderr
|
||||||
|
|
||||||
|
|
||||||
def test_doctor_and_monitor_roots_are_lazy_identity_preserving_facades():
|
def test_doctor_and_monitor_roots_are_lazy_identity_preserving_facades(tmp_path):
|
||||||
"""诊断和监控包根不得预载实现,旧路径仍需返回同一公开对象。"""
|
"""诊断和监控包根不得预载实现,旧路径仍需返回同一公开对象。"""
|
||||||
script = """
|
script = """
|
||||||
import sys
|
import sys
|
||||||
@@ -176,6 +177,11 @@ import app.monitor
|
|||||||
assert not any(name.startswith('app.doctor.') for name in sys.modules)
|
assert not any(name.startswith('app.doctor.') for name in sys.modules)
|
||||||
assert not any(name.startswith('app.monitor.') for name in sys.modules)
|
assert not any(name.startswith('app.monitor.') for name in sys.modules)
|
||||||
|
|
||||||
|
# CI 无 app.application.site.sites 资源模块,触发实现加载前先补 conftest 同源垫片;
|
||||||
|
# 独立子进程不经过 pytest 引导,必须在此显式安装,否则链式 import 会因缺模块失败。
|
||||||
|
from app.testing.bootstrap import ensure_sites_stub
|
||||||
|
ensure_sites_stub()
|
||||||
|
|
||||||
from app.doctor import DoctorRunner, run_doctor
|
from app.doctor import DoctorRunner, run_doctor
|
||||||
from app.doctor.runner import DoctorRunner as DirectDoctorRunner
|
from app.doctor.runner import DoctorRunner as DirectDoctorRunner
|
||||||
from app.monitor import LocalDirectoryWatcher, Monitor
|
from app.monitor import LocalDirectoryWatcher, Monitor
|
||||||
@@ -187,9 +193,11 @@ assert Monitor is DirectMonitor
|
|||||||
assert LocalDirectoryWatcher is DirectWatcher
|
assert LocalDirectoryWatcher is DirectWatcher
|
||||||
assert callable(run_doctor)
|
assert callable(run_doctor)
|
||||||
"""
|
"""
|
||||||
|
env = {**os.environ, "CONFIG_DIR": str(tmp_path / "config")}
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
[sys.executable, "-c", script],
|
[sys.executable, "-c", script],
|
||||||
cwd=PROJECT_ROOT,
|
cwd=PROJECT_ROOT,
|
||||||
|
env=env,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
check=False,
|
check=False,
|
||||||
|
|||||||
Reference in New Issue
Block a user