From fa69c5b2e04cebca07bde14e890796d0bad8575f Mon Sep 17 00:00:00 2001 From: Mariia Borodii Date: Tue, 25 Aug 2026 06:33:40 +0000 Subject: [PATCH 1/3] Fix caplog not capturing INFO logs in train model cleanup tests test_classify_write_logs_new_model_id_integration, test_lookup_write_logs_new_model_id, and test_standardize_write_logs_new_model_id create real models via name: and rely on caplog to find the "New model created" log line to delete them in a finally block. pytest's caplog fixture only captures WARNING+ by default, so the INFO record was never created and the cleanup silently no-op'd, leaking a new model on every run. --- tests/connectors/test_train.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/connectors/test_train.py b/tests/connectors/test_train.py index 6cf8bd01..b4f77cd1 100644 --- a/tests/connectors/test_train.py +++ b/tests/connectors/test_train.py @@ -142,6 +142,7 @@ def test_classify_read_four_cols_error(mocker): ) def test_classify_write_logs_new_model_id_integration(caplog): + caplog.set_level(logging.INFO) df = pd.DataFrame({ 'Example': ['apple', 'banana'], 'Category': ['fruit', 'fruit'], @@ -1425,6 +1426,7 @@ def test_lookup_write_logs_new_model_id(caplog): """ Integration test for lookup model creation logging """ + caplog.set_level(logging.INFO) df = pd.DataFrame({ 'Key': ['apple', 'banana'], 'Value': ['fruit', 'fruit'] @@ -1535,6 +1537,7 @@ def test_standardize_write_logs_new_model_id(caplog): """ Integration test for standardize model creation logging """ + caplog.set_level(logging.INFO) df = pd.DataFrame({ 'Find': ['ASAP', 'ETA'], 'Replace': ['As Soon As Possible', 'Estimated Time of Arrival'], From 23cb11e4307b87e1b0967eeefb0c9b99464daa6b Mon Sep 17 00:00:00 2001 From: mborodii-prog Date: Tue, 25 Aug 2026 14:24:20 +0300 Subject: [PATCH 2/3] Update test_recipes.py --- tests/recipes/test_recipes.py | 72 +++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/tests/recipes/test_recipes.py b/tests/recipes/test_recipes.py index b2e09ef5..38097262 100644 --- a/tests/recipes/test_recipes.py +++ b/tests/recipes/test_recipes.py @@ -127,11 +127,36 @@ def test_recipe_by_version_tag(): ) -def test_recipe_by_production_version(): +def test_recipe_by_production_version(mocker): """ Test running a recipe using a model ID and production version """ + mocker.patch( + "wrangles.data.model", + return_value={ + "purpose": "recipe", + "production_version_id": "production-version-id" + } + ) + model_content = mocker.patch( + "wrangles.data.model_content", + return_value={ + "recipe": """ + read: + - test: + rows: 20 + values: + header: value1 + """ + } + ) + df = wrangles.recipe.run("a6bac9e7-2388-4347") + + model_content.assert_called_once_with( + "a6bac9e7-2388-4347", + "production-version-id" + ) assert ( len(df) == 20 and list(df.columns) == ["header"] @@ -184,21 +209,62 @@ def test_recipe_by_production_semantic_version_falls_back_to_latest( assert "No production version exists, defaulting to latest version" in caplog.text -def test_recipe_by_version_latest(): +def test_recipe_by_version_latest(mocker): """ Test running a recipe using a model ID and latest version """ + mocker.patch( + "wrangles.data.model", + return_value={ + "purpose": "recipe", + "production_version_id": "production-version-id" + } + ) + model_content = mocker.patch( + "wrangles.data.model_content", + return_value={ + "recipe": """ + read: + - test: + rows: 10 + values: + header: value1 + """ + } + ) + df = wrangles.recipe.run("a6bac9e7-2388-4347:latest") + + model_content.assert_called_once_with("a6bac9e7-2388-4347", None) assert ( len(df) == 10 and list(df.columns) == ["header"] ) -def test_recipe_by_latest_version(): +def test_recipe_by_latest_version(mocker): """ Test running a recipe using a model ID and latest version """ + mocker.patch( + "wrangles.data.model", + return_value={"purpose": "recipe"} + ) + model_content = mocker.patch( + "wrangles.data.model_content", + return_value={ + "recipe": """ + read: + - test: + rows: 15 + values: + header: value1 + """ + } + ) + df = wrangles.recipe.run("02fc0c63-1294-415b") + + model_content.assert_called_once_with("02fc0c63-1294-415b", None) assert ( len(df) == 15 and list(df.columns) == ["header"] From 389be83ddfdf2e715087e2badd978e13cecaacd1 Mon Sep 17 00:00:00 2001 From: mborodii-prog Date: Wed, 26 Aug 2026 11:44:00 +0300 Subject: [PATCH 3/3] Update test_recipes.py --- tests/recipes/test_recipes.py | 86 ++++------------------------------- 1 file changed, 10 insertions(+), 76 deletions(-) diff --git a/tests/recipes/test_recipes.py b/tests/recipes/test_recipes.py index 38097262..172d9fe5 100644 --- a/tests/recipes/test_recipes.py +++ b/tests/recipes/test_recipes.py @@ -127,36 +127,11 @@ def test_recipe_by_version_tag(): ) -def test_recipe_by_production_version(mocker): +def test_recipe_by_production_version(): """ Test running a recipe using a model ID and production version """ - mocker.patch( - "wrangles.data.model", - return_value={ - "purpose": "recipe", - "production_version_id": "production-version-id" - } - ) - model_content = mocker.patch( - "wrangles.data.model_content", - return_value={ - "recipe": """ - read: - - test: - rows: 20 - values: - header: value1 - """ - } - ) - - df = wrangles.recipe.run("a6bac9e7-2388-4347") - - model_content.assert_called_once_with( - "a6bac9e7-2388-4347", - "production-version-id" - ) + df = wrangles.recipe.run("e954717c-fb9c-4c47") assert ( len(df) == 20 and list(df.columns) == ["header"] @@ -179,10 +154,10 @@ def test_recipe_by_production_semantic_version(mocker): return_value={"recipe": "{}"} ) - wrangles.recipe.run("a6bac9e7-2388-4347:production") + wrangles.recipe.run("e954717c-fb9c-4c47:production") model_content.assert_called_once_with( - "a6bac9e7-2388-4347", + "e954717c-fb9c-4c47", "production-version-id" ) @@ -203,68 +178,27 @@ def test_recipe_by_production_semantic_version_falls_back_to_latest( return_value={"recipe": "{}"} ) - wrangles.recipe.run("a6bac9e7-2388-4347:production") + wrangles.recipe.run("e954717c-fb9c-4c47:production") - model_content.assert_called_once_with("a6bac9e7-2388-4347", None) + model_content.assert_called_once_with("e954717c-fb9c-4c47", None) assert "No production version exists, defaulting to latest version" in caplog.text -def test_recipe_by_version_latest(mocker): +def test_recipe_by_version_latest(): """ Test running a recipe using a model ID and latest version """ - mocker.patch( - "wrangles.data.model", - return_value={ - "purpose": "recipe", - "production_version_id": "production-version-id" - } - ) - model_content = mocker.patch( - "wrangles.data.model_content", - return_value={ - "recipe": """ - read: - - test: - rows: 10 - values: - header: value1 - """ - } - ) - - df = wrangles.recipe.run("a6bac9e7-2388-4347:latest") - - model_content.assert_called_once_with("a6bac9e7-2388-4347", None) + df = wrangles.recipe.run("e954717c-fb9c-4c47:latest") assert ( len(df) == 10 and list(df.columns) == ["header"] ) -def test_recipe_by_latest_version(mocker): +def test_recipe_by_latest_version(): """ Test running a recipe using a model ID and latest version """ - mocker.patch( - "wrangles.data.model", - return_value={"purpose": "recipe"} - ) - model_content = mocker.patch( - "wrangles.data.model_content", - return_value={ - "recipe": """ - read: - - test: - rows: 15 - values: - header: value1 - """ - } - ) - - df = wrangles.recipe.run("02fc0c63-1294-415b") - - model_content.assert_called_once_with("02fc0c63-1294-415b", None) + df = wrangles.recipe.run("1b41d016-7129-4b66") assert ( len(df) == 15 and list(df.columns) == ["header"]