diff --git a/tests/conftest.py b/tests/conftest.py index e7d2f76..a1e4aca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ +import os import uuid +import atexit import pytest from pathlib import Path from fastapi.testclient import TestClient @@ -49,3 +51,43 @@ def client_with_isolation(isolated_data_root): yield client utils.get_data_root = original + + +# ── E2E gate ── + +skip_no_integration = pytest.mark.skipif( + not os.environ.get("RUN_INTEGRATION"), + reason="Set RUN_INTEGRATION=1 to run E2E tests against real daemon", +) + + +# ── atexit 兜底清理 ── + +def _emergency_cleanup(): + """进程退出时的最后防线:清理所有 e2e- 前缀的测试数据""" + try: + import requests + api_base = os.environ.get("API_BASE", "http://localhost:8083") + # 清理 e2e 前缀项目 + resp = requests.get(f"{api_base}/api/projects", timeout=5) + if resp.ok: + for proj in resp.json(): + pid = proj.get("id", "") + if pid.startswith("e2e-"): + try: + requests.delete( + f"{api_base}/api/projects/{pid}?physical=true", + timeout=5, + ) + except Exception: + pass + # 清理 e2e 前缀邮件 + try: + requests.delete(f"{api_base}/api/mail?prefix=e2e-", timeout=5) + except Exception: + pass + except Exception: + pass + + +atexit.register(_emergency_cleanup)