Files
blackbird/pybot/tests/conftest.py
T
qing b289e7d17c fix(pybot): Windows 测试环境兼容(scripts 软链解析、os.pathsep 分隔)
- conftest:pybot/scripts 为 git 符号链接,Windows 落盘为文本文件(内容=目标相对路径),测试时手动解析到 bot4cj/scripts

- plugin:PYBOT_MODULES_PATH 改按 os.pathsep 分隔,避免 Windows 盘符冒号被切碎导致 find_module 返回丢盘符的路径
2026-08-14 09:34:26 +08:00

34 lines
844 B
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.
"""pytest 公共配置:把项目根加入 sys.path(无需安装即可 import pybot)"""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
import pytest # noqa: E402
from pybot.hd import i2c, spi # noqa: E402
SCRIPTS_DIR = ROOT / "scripts"
if not SCRIPTS_DIR.is_dir():
# Windows:git 符号链接落盘为文本文件(内容 = 目标相对路径),手动解析
SCRIPTS_DIR = (ROOT / SCRIPTS_DIR.read_text().strip()).resolve()
@pytest.fixture()
def mock_i2c():
"""切换到 Mock I2C 总线,测试结束恢复真实后端"""
mock = i2c.use_mock()
yield mock
i2c.use_real()
@pytest.fixture()
def mock_spi():
"""切换到 Mock SPI 总线,测试结束恢复真实后端"""
mock = spi.use_mock()
yield mock
spi.use_real()