stock-analysis-api / tests /conftest.py
vjeai's picture
Deploy: all fixes β€” yfinance candles, ml_signal 2y history, no handoff schemas, sequential report phase
3be03dd
Raw
History Blame Contribute Delete
1.37 kB
"""
tests/conftest.py
Stubs out heavy external packages that are not installed in the CI / test
environment β€” yfinance, sklearn, joblib β€” so that backend.main and the tool
modules can be imported without errors. Each stub is only injected when the
real package is absent; if the package IS installed the real one is used.
"""
import sys
from unittest.mock import MagicMock
# ── Packages to stub when not installed ───────────────────────────────────────
_OPTIONAL = [
"yfinance",
# sklearn and every sub-module that tool_ml_signal imports at the top level
"sklearn",
"sklearn.ensemble",
"sklearn.linear_model",
"sklearn.preprocessing",
"sklearn.model_selection",
"sklearn.calibration",
"sklearn.feature_selection",
"sklearn.metrics",
# joblib (used by sklearn internally and by tool_ml_signal.py)
"joblib",
# dotenv (python-dotenv) used in config/settings.py
"dotenv",
# autogen_ext used in config/settings.py model clients
"autogen_ext",
"autogen_ext.models",
"autogen_ext.models.openai",
"autogen_ext.models.anthropic",
]
for _pkg in _OPTIONAL:
if _pkg not in sys.modules:
try:
__import__(_pkg)
except ModuleNotFoundError:
sys.modules[_pkg] = MagicMock()