From ea7a60a460f0fec5c9c37165ceb72de0e78a84d1 Mon Sep 17 00:00:00 2001 From: thzxx <1440196015@qq.com> Date: Sat, 1 Aug 2026 20:57:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20subprocess=20=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20encoding=3Dutf-8=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20Windows=20GBK=20=E8=A7=A3=E7=A0=81=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _run_cli 辅助函数的 subprocess.run 用 text=True 但未指定 encoding,Windows 中文系统默认用 GBK 解码子进程输出,--help 的非 ASCII 字符(box-drawing/em-dash)触发 UnicodeDecodeError。显式指定 encoding='utf-8' 与脚本的 force_utf8_stdout() 对齐。 测试: 362/362 全部通过 --- tests/test_cli_e2e.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_cli_e2e.py b/tests/test_cli_e2e.py index 5f5c0fc..56b207f 100644 --- a/tests/test_cli_e2e.py +++ b/tests/test_cli_e2e.py @@ -242,12 +242,18 @@ def _run_cli(*args, env=None): Uses ``sys.executable`` so the same interpreter that runs pytest runs the CLI. cwd is pinned to PROJECT_ROOT so the script's config-file auto-discovery (./searxng.toml) behaves deterministically. + + ``encoding="utf-8"`` is explicit because Windows Chinese systems default + to GBK for subprocess text decoding, which crashes on non-ASCII chars + in --help output (e.g. box-drawing chars, em-dashes). The script itself + already forces UTF-8 stdout via ``force_utf8_stdout()``, so this just + matches the decoding side. """ full_env = {**os.environ, **(env or {})} cmd = [sys.executable, str(PROJECT_ROOT / "scripts" / "search.py")] + list(args) return subprocess.run( cmd, cwd=str(PROJECT_ROOT), - capture_output=True, text=True, timeout=30, + capture_output=True, text=True, encoding="utf-8", timeout=30, env=full_env, )