A comprehensive testing suite for validating MLflow model serving endpoints (mlflow serve) in iris classification scenarios. Ensures endpoint reliability and prediction consistency.
This approach is ideal for lightweight applications or for testing your model locally before moving it to a staging or production environment.
- Mehmet Acikgoz
- Maria Vechtomova
- Python ≥3.11
- MLflow model artifact (
pyfunc-lg-pipeline-modeldirectory)
-
Install dependencies
uv sync --all-extras -
Launch MLflow Server
uv run mlflow models serve -m pyfunc-lg-pipeline-model --port 5088 -
Run Test Suite (in new terminal)
uv run pytest tests/
| Feature | Verification Points |
|---|---|
| Service Health | ✅ 200 status on /health endpoint |
| Server Responsiveness | ✅ Successful /ping responses |
| Version Integrity | ✅ MLflow 2.17.0 confirmation |
| Prediction Formats | ✅ Supports both dataframe_split and dataframe_records |
- Class Validation: Ensures predictions {setosa, versicolor, virginica}
- Null Handling: Robust null value processing
- Batch Testing: CSV dataset validation (
test_data/test_set.csv) - Diagnostics: Detailed logging with
loguru
| Endpoint | Method | Success Criteria |
|---|---|---|
/health |
GET | HTTP 200 |
/ping |
GET | HTTP 200 |
/version |
GET | Returns "2.17.0" |
/invocations |
POST | Valid prediction JSON |
-
Single Prediction
- Validates response structure
- Tests both DataFrame serialization formats
-
Batch Validation
- Processes full CSV dataset
- Verifies class membership for all predictions
.
├── pyfunc-lg-pipeline-model/ # MLflow model artifacts
│ ├── MLmodel # Model metadata
│ ├── code/ # Custom code
│ ├── python_model.pkl # Serialized model
│ └── ... # Additional model files
├── tests/
│ ├── test_data/ # Test datasets
│ │ └── test_set.csv # Validation samples
│ └── test_mlflow_serve.py # Core test suite
├── pyproject.toml # Build configuration
└── README.md # This documentation
mlflow==2.17.0
virtualenv>=20.30.0
loguru>=0.7.3
pandas>=2.2.3
pytest>=8.3.5
requests>=2.32.3
- Port Conflicts: Ensure port 5088 is available
- Model Path: Verify
pyfunc-lg-pipeline-modeldirectory exists - Dependency Issues: Use
uv sync --all-extrasfor clean installs