fix(test): subprocess 显式指定 encoding=utf-8,修复 Windows GBK 解码崩溃
_run_cli 辅助函数的 subprocess.run 用 text=True 但未指定 encoding,Windows 中文系统默认用 GBK 解码子进程输出,--help 的非 ASCII 字符(box-drawing/em-dash)触发 UnicodeDecodeError。显式指定 encoding='utf-8' 与脚本的 force_utf8_stdout() 对齐。 测试: 362/362 全部通过
This commit is contained in:
@@ -242,12 +242,18 @@ def _run_cli(*args, env=None):
|
|||||||
Uses ``sys.executable`` so the same interpreter that runs pytest runs
|
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
|
the CLI. cwd is pinned to PROJECT_ROOT so the script's config-file
|
||||||
auto-discovery (./searxng.toml) behaves deterministically.
|
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 {})}
|
full_env = {**os.environ, **(env or {})}
|
||||||
cmd = [sys.executable, str(PROJECT_ROOT / "scripts" / "search.py")] + list(args)
|
cmd = [sys.executable, str(PROJECT_ROOT / "scripts" / "search.py")] + list(args)
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
cmd, cwd=str(PROJECT_ROOT),
|
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,
|
env=full_env,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user