Skip to content

Use cached_db fixture in tests/tracking/test_log_image.py for faster execution#19212

Merged
harupy merged 3 commits intomasterfrom
copilot/use-cached-db-fixture-tests
Dec 4, 2025
Merged

Use cached_db fixture in tests/tracking/test_log_image.py for faster execution#19212
harupy merged 3 commits intomasterfrom
copilot/use-cached-db-fixture-tests

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

Adopts the cached_db fixture pattern to eliminate repeated database schema migrations in test_log_image.py, reducing execution time from 29.5s to 7.1s (76% improvement).

Changes:

  • Added set_tracking_uri autouse fixture that copies session-scoped cached_db to test-local temporary paths
  • Uses _use_tracking_uri context manager for automatic URI lifecycle management
  • Each test gets isolated database copy via uuid.uuid4().hex naming

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

All 47 existing tests pass with identical behavior.

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)
Original prompt

Use cached_db fixture in tests/tracking/test_log_image.py for faster test execution

diff --git a/tests/tracking/test_log_image.py b/tests/tracking/test_log_image.py
index dcf1b18502..036eb73a3d 100644
--- a/tests/tracking/test_log_image.py
+++ b/tests/tracking/test_log_image.py
@@ -1,14 +1,26 @@
 import json
 import os
 import posixpath
+import shutil
+import uuid
+from pathlib import Path
 
 import pytest
 
 import mlflow
+from mlflow.tracking._tracking_service.utils import _use_tracking_uri
 from mlflow.utils.file_utils import local_file_uri_to_path
 from mlflow.utils.time import get_current_time_millis
 
 
+@pytest.fixture(autouse=True)
+def set_tracking_uri(tmp_path: Path, cached_db: Path):
+    db_path = tmp_path / f"{uuid.uuid4().hex}.sqlite"
+    shutil.copy(cached_db, db_path)
+    with _use_tracking_uri(f"sqlite:///{db_path}"):
+        yield
+
+
 @pytest.mark.parametrize("subdir", [None, ".", "dir", "dir1/dir2", "dir/.."])
 def test_log_image_numpy(subdir):
     import numpy as np

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…test execution

Co-authored-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy marked this pull request as ready for review December 4, 2025 13:09
Copilot AI review requested due to automatic review settings December 4, 2025 13:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the cached_db fixture to tests/tracking/test_log_image.py to improve test execution performance by avoiding repeated database migrations. The implementation achieves a 76% reduction in test execution time (29.5s → 7.1s).

Key Changes

  • Added imports for shutil, uuid, Path, and _use_tracking_uri to support database caching functionality
  • Introduced an autouse fixture set_tracking_uri that copies a pre-initialized database and sets the tracking URI for each test
  • Applied the cached database pattern to avoid expensive database setup operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI changed the title [WIP] Use cached_db fixture for faster test execution Use cached_db fixture in tests/tracking/test_log_image.py for 76% faster execution Dec 4, 2025
Copilot AI requested a review from harupy December 4, 2025 13:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Harutaka Kawamura <hkawamura0130@gmail.com>
@harupy harupy changed the title Use cached_db fixture in tests/tracking/test_log_image.py for 76% faster execution Use cached_db fixture in tests/tracking/test_log_image.py for faster execution Dec 4, 2025
@github-actions github-actions bot added area/build Build and test infrastructure for MLflow rn/none List under Small Changes in Changelogs. labels Dec 4, 2025
@harupy harupy added this pull request to the merge queue Dec 4, 2025
Merged via the queue into master with commit 15d9f46 Dec 4, 2025
47 of 50 checks passed
@harupy harupy deleted the copilot/use-cached-db-fixture-tests branch December 4, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Build and test infrastructure for MLflow rn/none List under Small Changes in Changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants