Skip to content

Commit

Permalink
No cuddling
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 11, 2024
1 parent b259fd0 commit cd06463
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 80 deletions.
141 changes: 61 additions & 80 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
import pathlib
from unittest.mock import patch

# Configure logging
logging.basicConfig(
level=logging.DEBUG, # Set the logging level to DEBUG for verbose output
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)

_logger = logging.getLogger(__name__)
_logger.setLevel(logging.DEBUG) # Ensure the specific logger outputs DEBUG-level logs


def load_new_function(file_path, func_name):
with open(file_path) as f:
Expand All @@ -22,77 +15,65 @@ def load_new_function(file_path, func_name):


def pytest_configure(config):
try:
for func_to_patch, new_func_file_relative in (
(
"tests.tracking.integration_test_utils._init_server",
"tests/override_server.py",
),
(
"mlflow.store.tracking.sqlalchemy_store.SqlAlchemyStore",
"tests/override_tracking_store.py",
),
(
"mlflow.store.model_registry.sqlalchemy_store.SqlAlchemyStore",
"tests/override_model_registry_store.py",
),
# This test will patch some Python internals to invoke an internal exception.
# We cannot do this in Go.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_internal_error",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_params_max_length_value",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_param_max_length_value",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_set_tag",
"tests/override_test_sqlalchemy_store.py",
),
# This tests calls the store using invalid metric entity that cannot be converted
# to its proto counterpart.
# Example: entities.Metric("invalid_metric", None, (int(time.time() * 1000)), 0).to_proto()
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_null_metrics",
"tests/override_test_sqlalchemy_store.py",
),
# We do not support applying the SQL schema to sqlite like Python does.
# So we do not support sqlite:////:memory: database.
(
"tests.store.tracking.test_sqlalchemy_store.test_sqlalchemy_store_behaves_as_expected_with_inmemory_sqlite_db",
"tests/override_test_sqlalchemy_store.py",
), # We do not support applying the SQL schema to sqlite like Python does.
# So we do not support sqlite:////:memory: database.
(
"tests.store.tracking.test_sqlalchemy_store.test_search_experiments_max_results_validation",
"tests/override_test_sqlalchemy_store.py",
),
(
"tests.store.tracking.test_sqlalchemy_store.test_search_experiments_filter_by_time_attribute",
"tests/override_test_sqlalchemy_store.py",
),
(
"tests.store.tracking.test_sqlalchemy_store.test_search_experiments_order_by_time_attribute",
"tests/override_test_sqlalchemy_store.py",
),
):
func_name = func_to_patch.rsplit(".", 1)[1]
new_func_file = (
pathlib.Path(__file__).parent.joinpath(new_func_file_relative).resolve().as_posix()
)
for func_to_patch, new_func_file_relative in (
(
"tests.tracking.integration_test_utils._init_server",
"tests/override_server.py",
),
(
"mlflow.store.tracking.sqlalchemy_store.SqlAlchemyStore",
"tests/override_tracking_store.py",
),
(
"mlflow.store.model_registry.sqlalchemy_store.SqlAlchemyStore",
"tests/override_model_registry_store.py",
),
# This test will patch some Python internals to invoke an internal exception.
# We cannot do this in Go.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_internal_error",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_params_max_length_value",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_log_param_max_length_value",
"tests/override_test_sqlalchemy_store.py",
),
# This test uses monkeypatch.setenv which does not flow through to the Go side.
(
"tests.store.tracking.test_sqlalchemy_store.test_set_tag",
"tests/override_test_sqlalchemy_store.py",
),
# This tests calls the store using invalid metric entity that cannot be converted
# to its proto counterpart.
# Example: entities.Metric("invalid_metric", None, (int(time.time() * 1000)), 0).to_proto()
(
"tests.store.tracking.test_sqlalchemy_store.test_log_batch_null_metrics",
"tests/override_test_sqlalchemy_store.py",
),
# We do not support applying the SQL schema to sqlite like Python does.
# So we do not support sqlite:////:memory: database.
(
"tests.store.tracking.test_sqlalchemy_store.test_sqlalchemy_store_behaves_as_expected_with_inmemory_sqlite_db",
"tests/override_test_sqlalchemy_store.py",
), # We do not support applying the SQL schema to sqlite like Python does.
# So we do not support sqlite:////:memory: database.
(
"tests.store.tracking.test_sqlalchemy_store.test_search_experiments_max_results_validation",
"tests/override_test_sqlalchemy_store.py",
),
):
func_name = func_to_patch.rsplit(".", 1)[1]
new_func_file = (
pathlib.Path(__file__).parent.joinpath(new_func_file_relative).resolve().as_posix()
)

new_func = load_new_function(new_func_file, func_name)
new_func = load_new_function(new_func_file, func_name)

_logger.info(f"Patching function: {func_to_patch}")
patch(func_to_patch, new_func).start()
except Exception as e:
_logger.error(f"Error in pytest_configure: {e}")
raise
_logger.info(f"Patching function: {func_to_patch}")
patch(func_to_patch, new_func).start()
1 change: 1 addition & 0 deletions magefiles/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func runPythonTests(pytestArgs []string) error {

executable := "uv"
args := []string{"run", "pytest"}

if runtime.GOOS == "darwin" {
executable = ".venv/bin/pytest"
args = []string{}
Expand Down

0 comments on commit cd06463

Please sign in to comment.