init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
pytest 配置文件
|
||||
|
||||
提供全局的 fixtures 和配置
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def project_dir() -> Path:
|
||||
"""获取项目根目录"""
|
||||
return project_root
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def config_dir() -> Path:
|
||||
"""获取配置目录"""
|
||||
return project_root / "config"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_user_input() -> str:
|
||||
"""示例用户输入"""
|
||||
return "你好,帮我查询订单信息"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_sql() -> str:
|
||||
"""示例 SQL 语句"""
|
||||
return "SELECT * FROM orders LIMIT 10"
|
||||
|
||||
|
||||
# 自动使用的 fixture(可选)
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_environment():
|
||||
"""为所有测试设置环境变量"""
|
||||
# 可以在这里设置测试环境变量
|
||||
os.environ.setdefault("TESTING", "true")
|
||||
yield
|
||||
# 清理(如果需要)
|
||||
if "TESTING" in os.environ:
|
||||
del os.environ["TESTING"]
|
||||
Reference in New Issue
Block a user