auto-sync: 2026-06-05 11:03:30
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import uuid
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
markers = {
|
||||
"unit": "单元测试:纯逻辑,mock 外部依赖",
|
||||
"integration": "集成测试:API 端点 + 真实/临时 DB",
|
||||
"e2e": "端到端测试:真实 daemon + Agent(手动触发)",
|
||||
"slow": "慢测试(>5s)",
|
||||
"broadcast": "广播认领相关",
|
||||
"mail": "邮件系统相关",
|
||||
"state_machine": "状态机转换",
|
||||
"classify": "Classify Outcome 相关",
|
||||
"review": "审查/Rebuttal 相关",
|
||||
}
|
||||
for name, desc in markers.items():
|
||||
config.addinivalue_line("markers", f"{name}: {desc}")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def isolated_data_root(tmp_path):
|
||||
"""隔离的 data_root,测试结束自动清理"""
|
||||
data_root = tmp_path / "test_data"
|
||||
data_root.mkdir()
|
||||
return data_root
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def isolated_registry(isolated_data_root):
|
||||
"""隔离的 registry.db"""
|
||||
from src.blackboard.registry import ProjectRegistry
|
||||
registry = ProjectRegistry(isolated_data_root)
|
||||
return registry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client_with_isolation(isolated_data_root):
|
||||
"""带数据隔离的 TestClient"""
|
||||
import src.utils as utils
|
||||
original = utils.get_data_root
|
||||
utils.get_data_root = lambda: isolated_data_root
|
||||
|
||||
from src.main import app
|
||||
client = TestClient(app)
|
||||
|
||||
yield client
|
||||
|
||||
utils.get_data_root = original
|
||||
Reference in New Issue
Block a user