File size: 1,003 Bytes
0feab1a
 
 
 
 
 
 
 
 
 
 
 
ee37d63
 
0feab1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee37d63
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
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"))