import importlib.util import sys import types from pathlib import Path def load_article_renderer(monkeypatch): """加载纯 HTML 构建逻辑,避免测试中启动 Chromium。""" pyppeteer = types.ModuleType("pyppeteer") pyppeteer.launch = None monkeypatch.setitem(sys.modules, "pyppeteer", pyppeteer) path = Path(__file__).resolve().parents[1] / "danding_bot" / "plugins" / "danding_qqpush" / "article_render.py" spec = importlib.util.spec_from_file_location("danding_qqpush_article_render", path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module def test_article_document_preserves_layout_and_removes_script(monkeypatch): module = load_article_renderer(monkeypatch) document = module.build_article_document( "

第一段

第二段

", "公告 <标题>", "2026-07-30 20:27", ) assert "

第一段

" in document assert "第二段" in document assert "

第二段

", "标题", None) assert "