File size: 828 Bytes
eab2256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
if str(SRC) not in sys.path:
    sys.path.insert(0, str(SRC))

import pytest

from twitter_sentiment.config import load_config
from twitter_sentiment.modeling import persist_artifacts, train_and_evaluate


@pytest.fixture(scope="session", autouse=True)
def ensure_artifacts():
    """Train and persist the pipeline if artifacts are absent."""

    config = load_config()
    artifact_dir = Path(config.model.get("artifact_dir", "artifacts"))
    artifact_path = artifact_dir / config.model.get("pipeline_filename", "sentiment_pipeline.joblib")

    if artifact_path.exists():
        return

    pipeline, metrics = train_and_evaluate(config)
    persist_artifacts(pipeline, config, metrics)