"""集成测试配置:MySQL/Redis 不可用或认证失败时自动跳过。""" import pytest def _services_available() -> bool: """尝试真实连接 MySQL 与 Redis,任一不可用则跳过集成测试。""" try: # 数据库连通性 + 认证(select(1) 跨方言,Oracle 下自动渲染 SELECT 1 FROM DUAL) from sqlalchemy import select from extensions.sqlalchemy import engine with engine.connect() as conn: conn.execute(select(1)) # Redis 连通性 from core.redis import redis redis.ping() return True except Exception: return False SERVICES_AVAILABLE = _services_available() @pytest.fixture(autouse=True) def _skip_without_services(request): """集成测试依赖 MySQL/Redis,服务不可用或认证失败时跳过。""" if "integration" in request.keywords and not SERVICES_AVAILABLE: pytest.skip("MySQL/Redis 服务不可用或认证失败,跳过集成测试")