DockerSpace / tests /conftest.py
DennisChan0909's picture
Backup current stock predictor strategies
ee37d63
Raw
History Blame Contribute Delete
1 kB
"""
Test configuration: mock heavy external dependencies so unit tests
can import service modules without requiring yfinance, sklearn, etc.
Only mocks modules that are NOT already importable — this way,
if sklearn/joblib are installed (e.g. for ML tests), they are used as-is.
"""
import importlib
import sys
from unittest.mock import MagicMock
import pytest
# Modules that are expensive / unavailable in test env.
# Only mock if they cannot be imported for real.
_MOCK_MODULES = [
"yfinance",
"twstock",
"sklearn",
"sklearn.ensemble",
"sklearn.model_selection",
"sklearn.preprocessing",
"joblib",
]
for mod_name in _MOCK_MODULES:
if mod_name not in sys.modules:
try:
importlib.import_module(mod_name)
except ImportError:
sys.modules[mod_name] = MagicMock()
@pytest.fixture(autouse=True)
def _closed_loop_log_tmpdir(monkeypatch, tmp_path):
monkeypatch.setenv("CLOSED_LOOP_LOG_DIR", str(tmp_path / "closed_loop_logs"))