add conftest.py with fixtures to prevent CI hangs

This commit is contained in:
Clayton Brown 2026-04-21 16:48:15 +10:00
parent fa4d01c23a
commit 41d239780c
1 changed files with 67 additions and 0 deletions

67
tests/conftest.py Normal file
View File

@ -0,0 +1,67 @@
"""Shared pytest fixtures that prevent CI hangs when API keys are absent."""
import os
from unittest.mock import MagicMock, patch
import pytest
# ---------------------------------------------------------------------------
# Custom markers
# ---------------------------------------------------------------------------
def pytest_configure(config):
for marker in ("unit", "integration", "smoke"):
config.addinivalue_line("markers", f"{marker}: {marker}-level tests")
# ---------------------------------------------------------------------------
# Auto-use: placeholder API keys so LLM client init never blocks
# ---------------------------------------------------------------------------
_API_KEY_ENV_VARS = [
"OPENAI",
"GOOGLE",
"ANTHROPIC",
"XAI",
"ALPHA_VANTAGE",
]
@pytest.fixture(autouse=True)
def _dummy_api_keys(monkeypatch):
for provider in _API_KEY_ENV_VARS:
env_var = f"{provider}_API_KEY"
monkeypatch.setenv(env_var, os.environ.get(env_var, "placeholder"))
# ---------------------------------------------------------------------------
# Auto-use: safe DEFAULT_CONFIG override (no real API calls)
# ---------------------------------------------------------------------------
_SAFE_CONFIG = {
"llm_provider": "openai",
"deep_think_llm": "gpt-5.4-mini",
"quick_think_llm": "gpt-5.4-mini",
"max_debate_rounds": 1,
"max_risk_discuss_rounds": 1,
}
@pytest.fixture(autouse=True)
def _safe_default_config():
with patch.dict("tradingagents.default_config.DEFAULT_CONFIG", _SAFE_CONFIG):
yield
# ---------------------------------------------------------------------------
# Reusable mock LLM client
# ---------------------------------------------------------------------------
@pytest.fixture()
def mock_llm_client():
client = MagicMock()
client.get_llm.return_value = MagicMock()
with patch("tradingagents.llm_clients.create_llm_client", return_value=client):
yield client