Skip to content

robust test suite for local dev (real PySide6 + non-UTF-8 Windows)#262

Open
Mizushima-Mihane wants to merge 3 commits into
RachelForster:mainfrom
Mizushima-Mihane:fix/test-suite-dev-env-robustness
Open

robust test suite for local dev (real PySide6 + non-UTF-8 Windows)#262
Mizushima-Mihane wants to merge 3 commits into
RachelForster:mainfrom
Mizushima-Mihane:fix/test-suite-dev-env-robustness

Conversation

@Mizushima-Mihane

Copy link
Copy Markdown
Contributor

Summary

Two independent, test-only fixes that let the suite pass in a full local dev
environment (Windows, PySide6 installed, non-UTF-8 / CP936 locale). Both only
fail outside CI, so CI stayed green while local pytest / the pre-push hook
went red.

1. test_chat_history clobbered a real PySide6 install

test/unit/core/test_chat_history.py faked PySide6/QtWidgets/QtCore into
sys.modules unconditionally via setdefault(). That only checks whether the
module is already imported, not installable — so on a machine with PySide6
installed but not yet imported, the mocks were planted and leaked into every
other test module, breaking real QtCore/QtGui imports
(QThreadDagNode(DagNode, QThread) → metaclass conflict) → 8 collection errors.
Fix: only fake PySide6 when it genuinely can't be imported.

2. runtime-check subprocess decoding crashed on non-UTF-8 output

test_desktop_core_runtime_check_... and test_ui_update_manager_import_does_not_require_cv2
capture a subprocess with encoding="utf-8". On a CP936 Windows box the child
emits GBK bytes in localized OS error strings, crashing the UTF-8 reader thread
and leaving result.stdout as None → 'NoneType'.strip().
Fix: add errors="replace"; the asserted JSON is ensure_ascii=True so it's unaffected.

Testing

pytest on Windows / Python 3.12 / PySide6 6.11.1: 1467 passed, 10 skipped
(previously 8 collection errors + 1 failure locally; CI unaffected).
📋 本次全部落定

test_chat_history planted MagicMock stubs for PySide6 into sys.modules
unconditionally at import time. On machines where PySide6 is installed but
not yet imported, setdefault() installed the Mocks anyway and leaked them
into every other test module in the same pytest process, breaking real
QtCore/QtGui imports (QThread metaclass conflict) and causing 8 collection
errors when the full suite runs.

Guard the fakes behind `try: import PySide6 / except ImportError` so a real
install is never clobbered. CI (no PySide6) still gets the fakes.
…-8 locales

test_desktop_core_runtime_check_does_not_import_optional_packages and
test_ui_update_manager_import_does_not_require_cv2 capture a subprocess with
encoding="utf-8". On a non-UTF-8 (e.g. Chinese CP936) Windows locale the child
can emit GBK bytes in localized OS error strings, which crashed the UTF-8 reader
thread and left result.stdout as None -> 'NoneType' object has no attribute 'strip'.

Add errors="replace" so decoding can't crash. The asserted JSON is printed with
ensure_ascii=True, so it is unaffected.
@ameath-review

ameath-review Bot commented Jul 23, 2026

Copy link
Copy Markdown

ℹ️ PR 快照已变化或关闭,本次旧快照审查已安全取消。新提交会由新的 webhook 任务审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants