|
9 | 9 | import sqlite3 |
10 | 10 |
|
11 | 11 | import pytest |
| 12 | +from pydantic import ValidationError |
12 | 13 |
|
13 | 14 | from tesseract_core.runtime import mpa |
14 | 15 | from tesseract_core.runtime.config import update_config |
@@ -293,3 +294,43 @@ def test_build_tracking_uri_sqlite_ignores_credentials(): |
293 | 294 | assert "testuser" not in tracking_uri |
294 | 295 | assert "testpass" not in tracking_uri |
295 | 296 | assert tracking_uri.startswith("sqlite:///") |
| 297 | + |
| 298 | + |
| 299 | +def test_mlflow_run_extra_args(mocker): |
| 300 | + """Test passing a dict with basic tags.""" |
| 301 | + pytest.importorskip("mlflow") |
| 302 | + |
| 303 | + kwargs = {"tags": {"env": "prod", "team": "ml"}} |
| 304 | + kwargs_str = repr(kwargs) |
| 305 | + |
| 306 | + update_config(mlflow_run_extra_args=kwargs_str) |
| 307 | + mocked_mlflow = mocker.Mock() |
| 308 | + |
| 309 | + backend = mpa.MLflowBackend() |
| 310 | + backend.mlflow = mocked_mlflow |
| 311 | + |
| 312 | + # Make sure kwargs are forwarded correctly to mlflow.start_run |
| 313 | + backend.start_run() |
| 314 | + mocked_mlflow.start_run.assert_called_with(**kwargs) |
| 315 | + |
| 316 | + |
| 317 | +def test_mlflow_run_extra_args_parsing(): |
| 318 | + # This is actually a test for config.py but we add it here for now |
| 319 | + |
| 320 | + with pytest.raises(ValidationError): |
| 321 | + # Not a valid Python object |
| 322 | + update_config(mlflow_run_extra_args="{'unbalanced dict': True") |
| 323 | + |
| 324 | + with pytest.raises(ValidationError): |
| 325 | + # Not a dict |
| 326 | + update_config(mlflow_run_extra_args="['this is a list']") |
| 327 | + |
| 328 | + with pytest.raises(ValidationError): |
| 329 | + # Not str keys |
| 330 | + update_config(mlflow_run_extra_args="{0: 'hey there'}") |
| 331 | + |
| 332 | + # All good |
| 333 | + update_config(mlflow_run_extra_args="{'hey there': 'general kenobi'}") |
| 334 | + |
| 335 | + # Passing dicts directly is fine, too |
| 336 | + update_config(mlflow_run_extra_args={"hey there": "general kenobi"}) |
0 commit comments