Skip to content

Optimize test_artifacts.py execution by using cached database fixture#19242

Merged
harupy merged 2 commits intomasterfrom
copilot/use-db-uri-fixture
Dec 5, 2025
Merged

Optimize test_artifacts.py execution by using cached database fixture#19242
harupy merged 2 commits intomasterfrom
copilot/use-db-uri-fixture

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

What changes are proposed in this pull request?

Test execution time reduced 44% (15.5s → 8.7s) by replacing per-test database migrations with a cached, pre-migrated database.

Changes:

  • Added tracking_uri autouse fixture that leverages db_uri fixture from conftest
  • Import _use_tracking_uri context manager to temporarily set tracking URI
  • All tests now share a session-cached SQLite database copied per test

Before: Each test created a new SQLite database and ran migrations
After: Tests copy a pre-migrated database, skipping migration overhead

@pytest.fixture(autouse=True)
def tracking_uri(db_uri: str):
    with _use_tracking_uri(db_uri):
        yield

How is this PR tested?

  • Existing unit/integration tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.

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

Components

  • area/build: Build and test infrastructure for MLflow

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

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 db_uri fixture in ests/artifacts/test_artifacts.py to skip database migration in each test for faster execution

diff --git a/tests/artifacts/test_artifacts.py b/tests/artifacts/test_artifacts.py
index fba4eab310..50b0ff5104 100644
--- a/tests/artifacts/test_artifacts.py
+++ b/tests/artifacts/test_artifacts.py
@@ -7,6 +7,7 @@ import pytest

import mlflow
from mlflow.exceptions import MlflowException
+from mlflow.tracking._tracking_service.utils import _use_tracking_uri
from mlflow.utils.file_utils import mkdir, path_to_local_file_uri
from mlflow.utils.os import is_windows

@@ -16,6 +17,12 @@ class Artifact(NamedTuple):
content: str

+@pytest.fixture(autouse=True)
+def tracking_uri(db_uri: str):

  • with _use_tracking_uri(db_uri):
  •    yield
    

@pytest.fixture
def run_with_artifact(tmp_path):
artifact_path = "test"


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

@harupy harupy marked this pull request as ready for review December 5, 2025 10:18
Copilot AI review requested due to automatic review settings December 5, 2025 10:18
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.

Copilot wasn't able to review any files in this pull request.


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

…r faster execution

Co-authored-by: harupy <17039389+harupy@users.noreply.github.com>
Copilot AI changed the title [WIP] Use db_uri fixture to skip database migration in tests Optimize test_artifacts.py execution by using cached database fixture Dec 5, 2025
Copilot AI requested a review from harupy December 5, 2025 10:27
@github-actions github-actions bot added area/build Build and test infrastructure for MLflow rn/none List under Small Changes in Changelogs. labels Dec 5, 2025
@harupy harupy enabled auto-merge December 5, 2025 10:44
@harupy harupy disabled auto-merge December 5, 2025 11:05
@harupy harupy merged commit 60847c9 into master Dec 5, 2025
50 of 54 checks passed
@harupy harupy deleted the copilot/use-db-uri-fixture branch December 5, 2025 11:05
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