cluster4npu/tests/conftest.py
abin 5aa374625f docs: add autoflow project docs and test infrastructure
- Add .autoflow/ with health check, PRD, Design Doc, TDD, progress tracking
- Add tests/conftest.py with PyQt5/KP SDK stubs for unit testing
- Add pytest config to pyproject.toml (pythonpath, import-mode, test naming)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 19:31:52 +08:00

47 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
tests/conftest.py — 單元測試環境設定。
此 conftest.py 位於 tests/ 目錄(非 Python 套件),
可在 root __init__.py 被觸發前完成 Mock 注入。
在沒有 Kneron NPU 硬體、PyQt5、NodeGraphQt 的環境下,
仍可測試 core/performance/ 的純 Python 邏輯。
"""
import sys
from unittest.mock import MagicMock
def _install_mock(name: str) -> None:
"""若模組尚未存在,安裝空 MagicMock 作為替代。"""
if name not in sys.modules:
sys.modules[name] = MagicMock()
# Kneron KP SDK需要硬體驅動程式
_install_mock("kp")
# NumPy可能未安裝
try:
import numpy # noqa: F401
except ImportError:
_install_mock("numpy")
# PyQt5 相關模組(需要 GUI 環境)
for _mod in [
"PyQt5",
"PyQt5.QtWidgets",
"PyQt5.QtCore",
"PyQt5.QtGui",
"PyQt5.QtChart",
]:
_install_mock(_mod)
# NodeGraphQt依賴 PyQt5
_install_mock("NodeGraphQt")
_install_mock("NodeGraphQt.constants")
_install_mock("NodeGraphQt.base")
_install_mock("NodeGraphQt.base.node")
# OpenCV可能未安裝
_install_mock("cv2")