执行摘要
- 一句话:简化 VeOmni 安装测试,移除对 sys.path 依赖
- 推荐动作:值得快速合并,修复 CI 失败,提高测试可靠性。不要求深入 review。
功能与动机
CI 环境中 veomni 已安装在 site-packages 中,原测试通过修改 sys.path 来模拟缺失不生效,导致测试失败。PR body 明确指出需要修复 test_install_without_veomni_raises 在 CI 中的失败。
实现拆解
- 修改
tests/utils/veomni/test_router_replay_on_cpu.py 中的 test_install_without_veomni_raises 函数。
- 删除原测试中删除多个 sys.modules 条目和操作 sys.path 的代码。
- 改用
mp.setitem(sys.modules, "veomni.utils.moe_router_replay", None) 直接触发 ImportError。
- 添加注释说明:设置 sys.modules[name] = None 即可让 Python import 引发 ImportError,无需操作 sys.path。
关键文件:
tests/utils/veomni/test_router_replay_on_cpu.py(模块 测试;类别 test;类型 test-coverage;符号 test_install_without_veomni_raises): 唯一变更文件,修改了模拟 VeOmni 缺失的测试方式,消除对 sys.path 的依赖
关键符号:test_install_without_veomni_raises
关键源码片段
tests/utils/veomni/test_router_replay_on_cpu.py
唯一变更文件,修改了模拟 VeOmni 缺失的测试方式,消除对 sys.path 的依赖
# tests/utils/veomni/test_router_replay_on_cpu.py (modified)
def test_install_without_veomni_raises(ctrl):
"""If the VeOmni hook surface is missing, install() must raise a
typed RuntimeError pointing the user at the dependency, not a raw
ImportError."""
with pytest.MonkeyPatch.context() as mp:
# 设置 sys.modules[name] = None 会让 Python 的 import 机制在
# `from veomni.utils.moe_router_replay import ...` 时抛出 ImportError,
# 无需操作 sys.path(当 veomni 安装在 site-packages 时无效)。
mp.setitem(sys.modules, "veomni.utils.moe_router_replay", None)
with pytest.raises(RuntimeError, match="VeOmni build"):
ctrl.install(nn.Linear(1, 1))
评论区精华
无人工 review 评论。代码审查机器人 gemini-code-assist 仅给出简化和背景说明,无反馈。
风险与影响
- 风险:低风险。仅修改单个测试文件的模拟方式,不涉及生产代码。新方法更简洁可靠,已在本地验证通过。
- 影响:影响范围小:仅针对 VeOmni 路由器重放相关测试,使其在 CI 环境中正确运行。
- 风险标记:暂无
关联脉络
参与讨论