From cd064639d743d26404b61769d2344977eefa9abf Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 11 Dec 2024 13:40:16 +0100 Subject: [PATCH] No cuddling --- conftest.py | 141 ++++++++++++++++++++------------------------- magefiles/tests.go | 1 + 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/conftest.py b/conftest.py index ce64e4e1..121dc431 100644 --- a/conftest.py +++ b/conftest.py @@ -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: @@ -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 \ No newline at end of file + _logger.info(f"Patching function: {func_to_patch}") + patch(func_to_patch, new_func).start() diff --git a/magefiles/tests.go b/magefiles/tests.go index c18ebdae..0ef058f5 100644 --- a/magefiles/tests.go +++ b/magefiles/tests.go @@ -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{}