From 1362cc5d64b3f89cae3e9c188f0d0399a6ba23a6 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sun, 21 Jun 2026 07:23:41 +0800 Subject: [PATCH] =?UTF-8?q?[moz]=20fix(test):=20=E4=BF=AE=E5=A4=8D=20integ?= =?UTF-8?q?ration/e2e=20=E6=B5=8B=E8=AF=95=20sys.path=20=E6=B1=A1=E6=9F=93?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20CI=20=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:4 个测试文件在模块级别执行 sys.path.insert(0, DEPLOY_DIR), 即使测试被 deselect/conftest 跳过,模块仍被 import 触发 sys.path 污染。 后续测试 import src 时从安装目录加载(缺少新增模块如 algorithms/)。 修复:在 sys.path 操作前加 allow_module_level skip guard, 未设置 RUN_INTEGRATION 时跳过整个模块,不执行任何模块级代码。 影响文件: - tests/integration/test_e2e_api_s1_s8.py - tests/e2e/test_e2e_stress.py - tests/e2e/test_e2e_scenarios.py - tests/e2e/test_e2e_v27.py --- tests/e2e/test_e2e_scenarios.py | 9 +++++++-- tests/e2e/test_e2e_stress.py | 9 +++++++-- tests/e2e/test_e2e_v27.py | 11 +++-------- tests/integration/test_e2e_api_s1_s8.py | 9 +++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/e2e/test_e2e_scenarios.py b/tests/e2e/test_e2e_scenarios.py index 2f470a5..8890ece 100644 --- a/tests/e2e/test_e2e_scenarios.py +++ b/tests/e2e/test_e2e_scenarios.py @@ -6,8 +6,14 @@ 需要 RUN_INTEGRATION=1 + 生产 daemon 运行。 """ -import json import os + +import pytest + +if not os.environ.get("RUN_INTEGRATION"): + pytest.skip("E2E tests require RUN_INTEGRATION=1", allow_module_level=True) + +import json import re import sqlite3 import sys @@ -17,7 +23,6 @@ from datetime import datetime, timedelta from pathlib import Path from typing import Any, Dict -import pytest import requests as http_requests # 指向部署目录 diff --git a/tests/e2e/test_e2e_stress.py b/tests/e2e/test_e2e_stress.py index 8cdefef..f21d8ea 100644 --- a/tests/e2e/test_e2e_stress.py +++ b/tests/e2e/test_e2e_stress.py @@ -4,15 +4,20 @@ 需要 RUN_INTEGRATION=1 + 生产 daemon 运行。 """ -import json import os + +import pytest + +if not os.environ.get("RUN_INTEGRATION"): + pytest.skip("E2E tests require RUN_INTEGRATION=1", allow_module_level=True) + +import json import sys import time import uuid from pathlib import Path from typing import Any, Dict, List -import pytest import requests as http_requests # 指向部署目录 diff --git a/tests/e2e/test_e2e_v27.py b/tests/e2e/test_e2e_v27.py index 8550afe..41168ae 100644 --- a/tests/e2e/test_e2e_v27.py +++ b/tests/e2e/test_e2e_v27.py @@ -1,11 +1,8 @@ import pytest +import os -skip_no_integration = pytest.mark.skipif( - not __import__("os").environ.get("RUN_INTEGRATION"), - reason="Set RUN_INTEGRATION=1 to run E2E tests against real daemon", -) - -pytestmark = [pytest.mark.e2e, skip_no_integration] +if not os.environ.get("RUN_INTEGRATION"): + pytest.skip("E2E tests require RUN_INTEGRATION=1", allow_module_level=True) """v2.7 端到端测试 — 全链路真实环境 @@ -14,7 +11,6 @@ pytestmark = [pytest.mark.e2e, skip_no_integration] import asyncio import json -import os import sys import time import uuid @@ -22,7 +18,6 @@ from datetime import datetime from pathlib import Path from typing import Any, Dict, List, Optional -import pytest from unittest.mock import MagicMock from fastapi.testclient import TestClient diff --git a/tests/integration/test_e2e_api_s1_s8.py b/tests/integration/test_e2e_api_s1_s8.py index 8785539..1724d2c 100644 --- a/tests/integration/test_e2e_api_s1_s8.py +++ b/tests/integration/test_e2e_api_s1_s8.py @@ -6,14 +6,19 @@ 覆盖:项目管理 → Task CRUD → SubTask → Stage 进度 → 父状态聚合 → 依赖链 → 超时 → Mail """ -import json import os + +import pytest + +if not os.environ.get("RUN_INTEGRATION"): + pytest.skip("Integration tests require RUN_INTEGRATION=1", allow_module_level=True) + +import json import sys import uuid from pathlib import Path from typing import Any, Dict -import pytest from unittest.mock import MagicMock from fastapi.testclient import TestClient