Files
gitadmin fda0fe1a53
CI / lint (push) Canceled after 0s
CI / test (push) Canceled after 0s
签入版本
2026-09-16 10:08:07 +08:00

29 lines
1001 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""集成测试配置: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 服务不可用或认证失败,跳过集成测试")