| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- """
- pytest 配置文件
- 定义全局 fixtures 和配置
- """
- import pytest
- import sys
- import os
- project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
- if project_root not in sys.path:
- @pytest.fixture(scope="session")
- def project_root_path():
- """返回项目根目录路径"""
- return project_root
- @pytest.fixture(scope="session")
- def test_data_dir():
- """返回测试数据目录路径"""
- return os.path.join(os.path.dirname(__file__), 'test_data')
- @pytest.fixture(autouse=True)
- def reset_environment():
- """每个测试前重置环境"""
- # 测试前的设置
- yield
- # 测试后的清理
- pass
- def pytest_configure(config):
- """pytest 配置钩子"""
- config.addinivalue_line(
- "markers", "integration: 标记集成测试(需要实际API服务)"
- )
- config.addinivalue_line(
- "markers", "slow: 标记慢速测试"
- )
- config.addinivalue_line(
- "markers", "unit: 标记单元测试"
- )
- def pytest_collection_modifyitems(config, items):
- """修改测试收集项"""
- for item in items:
- # 为所有异步测试添加 asyncio 标记
- if "asyncio" in item.keywords:
- item.add_marker(pytest.mark.asyncio)
|