Engineering
What this does: Validates every component with 50+ automated tests and >85% code coverage — from unit logic to infrastructure health — ensuring production reliability before any deployment.
Test Suite Overview
Unit & Integration
Validates core logic using
pytest. Covers drift detection, optimization, and API endpoints.Functional Verification
Specialized suite (
test_new_features.py) ensuring mathematical correctness of new logic like Feature Lags and CatBoost.Infrastructure Ops
Verifies operational components: SMTP alerts (
test_smtp_alerts.py), DAG integrity, and DB connections.Data Profiling
Hybrid Strategy: Lightweight Pandas checks for Airflow runtime vs. Deep Great Expectations profiling for development.
Running Tests
We use a custom test runnerrun_tests.py that wraps pytest with advanced reporting and coverage features.
1
Navigate to ML Service
All testing commands must be run from the
app-ml directory:2
Execute Test Runner
Run the comprehensive suite with the custom runner:
3
View Reports
The runner generates detailed artifacts:
- HTML Report:
test_reports/test_report.html(Summary & Recommendations) - Coverage:
coverage_report/index.html(Line-by-line analysis)
Key Test Categories
Production Operations
Critical validation for the automated MLOps layer.Functional Verification
Ensures the mathematical and logical correctness of specific features.- Feature Lags: Verifies correct shift logic (e.g.,
cnt_lag_1,hr_lag_2) and handling of resultingNaNvalues. - CatBoost Integration: Tests model training nodes and the
compare_modelslogic. - Metrics Parity: Validates the custom
compute_zero_safe_mapeimplementation against manual calculations to prevent division-by-zero errors.
Infrastructure Validation
Scripts located inapp-ml/scripts/ to verify the environment.
test_smtp_alerts.py: Sends a test email to verify SMTP credentials and template rendering.test_enhanced_dag.py: Parses the Airflow DAG to ensure no import errors or cyclic dependencies exist before deployment.verify_ml_integration.py: A “Smoke Test” that checks live connections to PostgreSQL, MinIO, and MLflow.
Data Quality Strategy
Runtime Validation (Airflow)
Tool: Pandas & Custom Logic
Why: Speed & Low Overhead.
Checks: Missing value % < 50%, Empty DataFrame checks, Column existence.
File:
dags/airflow_dag_enhanced.pyDeep Profiling (Dev)
Tool: Great Expectations
Why: Exploratory Data Analysis.
Checks: Full distribution analysis, quantile checks, detailed HTML reports.
File:
test_gx_profiling.pyCI/CD Integration
Therun_tests.py script returns a non-zero exit code if:
- Any test fails.
- Code coverage drops below 85%.
