""" pytest配置和fixture """ import pytest import asyncio from pathlib import Path from unittest.mock import Mock # 项目根目录 PROJECT_ROOT = Path(__file__).parent.parent @pytest.fixture(scope="session") def project_root(): """返回项目根目录""" return PROJECT_ROOT @pytest.fixture(scope="session") def test_data_dir(): """返回测试数据目录""" return PROJECT_ROOT / "tests" / "fixtures" @pytest.fixture def mock_llm_manager(): """模拟LLMManager""" llm = Mock() llm.call.return_value = Mock(content="test response") llm.acall.return_value = Mock(content="test response") return llm @pytest.fixture def mock_memory_manager(): """模拟MemoryManager""" memory = Mock() memory.add_message_to_session = Mock(return_value=asyncio.Future()) memory.add_message_to_session.return_value.set_result(None) return memory @pytest.fixture def event_loop(): """创建事件循环""" loop = asyncio.get_event_loop_policy().new_event_loop() yield loop loop.close() @pytest.fixture def sample_gene_family(): """示例基因家族数据""" return { "name": "SPL", "description": "SQUAMOSA PROMOTER BINDING PROTEIN-LIKE", "typical_size": 15, "key_domains": ["SBP"], } @pytest.fixture def sample_species(): """示例物种数据""" return { "code": "Ft", "name": "Arabidopsis", "full_name": "Arabidopsis thaliana", } # 标记测试类型 def pytest_configure(config): config.addinivalue_line("markers", "unit: Unit tests") config.addinivalue_line("markers", "integration: Integration tests") config.addinivalue_line("markers", "e2e: End-to-end tests")