- conftest:pybot/scripts 为 git 符号链接,Windows 落盘为文本文件(内容=目标相对路径),测试时手动解析到 bot4cj/scripts - plugin:PYBOT_MODULES_PATH 改按 os.pathsep 分隔,避免 Windows 盘符冒号被切碎导致 find_module 返回丢盘符的路径
34 lines
844 B
Python
34 lines
844 B
Python
"""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()
|