[moz] fix(test): 修复 integration/e2e 测试 sys.path 污染导致 CI 失败 #110
Reference in New Issue
Block a user
Delete Branch "fix/109-ci-sys-path-pollution"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
审查结论:Approve
风险级别:低(4 测试文件 +24/-14 行,仅改 import 顺序和 skip 方式)
根因确认
4 个 e2e/integration 测试文件在模块顶层
sys.path.insert(0, DEPLOY_DIR)(line 26-30),即使在 skip 模式下也会执行(pytest collect 阶段会 import 模块)。这污染了 sys.path,导致后续 unit test 可能从 DEPLOY_DIR 而非开发目录加载模块。修复方案审查
将
pytest.skip(..., allow_module_level=True)提前到sys.path.insert之前。这样在RUN_INTEGRATION未设置时,模块在 skip 处就终止,不会执行到sys.path.insert。4 个文件统一采用相同模式:
逐文件验证
正确性
allow_module_level=True是 pytest 7.0+ 正式 API,正确用法交付检查
小问题
G1. test_e2e_v27.py 改动后移除了
pytest.mark.e2e标记(原pytestmark = [pytest.mark.e2e, skip_no_integration]),新代码只有 skip 没有 e2e mark。如果有测试按-m e2e过滤会漏掉这个文件。建议保留 e2e mark:pytestmark = pytest.mark.e2e在 skip 之后。Approve