conftest.py 740 B

1234567891011121314151617181920212223242526
  1. """全局测试 fixtures。"""
  2. import pytest
  3. @pytest.fixture(scope="session")
  4. def config_handler():
  5. """会话级:配置读取器。"""
  6. from foundation.infrastructure.config.config import config_handler
  7. return config_handler
  8. @pytest.fixture(scope="session")
  9. def model_handler():
  10. """会话级:模型客户端管理器。"""
  11. from foundation.ai.models.model_handler import model_handler
  12. return model_handler
  13. @pytest.fixture
  14. async def redis_client():
  15. """函数级:Redis 连接(测试后自动清理)。"""
  16. from foundation.infrastructure.cache import RedisConnectionFactory
  17. client = RedisConnectionFactory.get()
  18. yield client
  19. for key in client.keys("test:*"):
  20. client.delete(key)