From 99f6e44c9fbeb8d7410e0e0b82ac79b624a912a7 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Mon, 18 Oct 2021 18:03:30 +0200 Subject: [PATCH 1/3] MAINT Shorten parametrized test names with long error messages --- sklearn/ensemble/tests/test_forest.py | 3 +++ sklearn/ensemble/tests/test_gradient_boosting.py | 3 +++ sklearn/linear_model/tests/test_sgd.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/sklearn/ensemble/tests/test_forest.py b/sklearn/ensemble/tests/test_forest.py index 02321310b5324..f4f34c8c3638a 100644 --- a/sklearn/ensemble/tests/test_forest.py +++ b/sklearn/ensemble/tests/test_forest.py @@ -1654,6 +1654,9 @@ def test_forest_degenerate_feature_importances(): r"'\'", ), ], + # Avoid long error messages in test names: + # https://github.com/scikit-learn/scikit-learn/issues/21362 + ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, ) def test_max_samples_exceptions(name, max_samples, exc_type, exc_msg): # Check invalid `max_samples` values diff --git a/sklearn/ensemble/tests/test_gradient_boosting.py b/sklearn/ensemble/tests/test_gradient_boosting.py index 410f4086bb7c4..d7f346d988435 100644 --- a/sklearn/ensemble/tests/test_gradient_boosting.py +++ b/sklearn/ensemble/tests/test_gradient_boosting.py @@ -105,6 +105,9 @@ def test_classification_toy(loss): ({"max_features": -0.1}, r"max_features must be in \(0, n_features\]"), ({"n_iter_no_change": "invalid"}, "n_iter_no_change should either be"), ], + # Avoid long error messages in test names: + # https://github.com/scikit-learn/scikit-learn/issues/21362 + ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, ) @pytest.mark.parametrize( "GradientBoosting, X, y", diff --git a/sklearn/linear_model/tests/test_sgd.py b/sklearn/linear_model/tests/test_sgd.py index 9b4c443ac1993..d0c4020967d20 100644 --- a/sklearn/linear_model/tests/test_sgd.py +++ b/sklearn/linear_model/tests/test_sgd.py @@ -248,6 +248,9 @@ def asgd(klass, X, y, eta, alpha, weight_init=None, intercept_init=0.0): ), ({"n_iter_no_change": 0}, "n_iter_no_change must be >= 1"), ], + # Avoid long error messages in test names: + # https://github.com/scikit-learn/scikit-learn/issues/21362 + ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, ) def test_sgd_estimator_params_validation(klass, fit_method, params, err_msg): """Validate parameters in the different SGD estimators.""" From 779e4d9473d4e6a16d23376a5ee7d351fd0c899a Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Tue, 19 Oct 2021 11:07:37 +0200 Subject: [PATCH 2/3] Keep a safe fragment of the original error message Co-authored-by: Thomas J. Fan --- sklearn/ensemble/tests/test_forest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/ensemble/tests/test_forest.py b/sklearn/ensemble/tests/test_forest.py index f4f34c8c3638a..e9b74f817311b 100644 --- a/sklearn/ensemble/tests/test_forest.py +++ b/sklearn/ensemble/tests/test_forest.py @@ -1656,7 +1656,7 @@ def test_forest_degenerate_feature_importances(): ], # Avoid long error messages in test names: # https://github.com/scikit-learn/scikit-learn/issues/21362 - ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, + ids=lambda x: x[:10].replace("]", "") if isinstance(x, str) else x, ) def test_max_samples_exceptions(name, max_samples, exc_type, exc_msg): # Check invalid `max_samples` values From 65b55769de26b92a1544ac9bf33a8042d203c9e2 Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Tue, 19 Oct 2021 12:17:06 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- sklearn/ensemble/tests/test_gradient_boosting.py | 2 +- sklearn/linear_model/tests/test_sgd.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/ensemble/tests/test_gradient_boosting.py b/sklearn/ensemble/tests/test_gradient_boosting.py index d7f346d988435..af164d61176f4 100644 --- a/sklearn/ensemble/tests/test_gradient_boosting.py +++ b/sklearn/ensemble/tests/test_gradient_boosting.py @@ -107,7 +107,7 @@ def test_classification_toy(loss): ], # Avoid long error messages in test names: # https://github.com/scikit-learn/scikit-learn/issues/21362 - ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, + ids=lambda x: x[:10].replace("]", "") if isinstance(x, str) else x, ) @pytest.mark.parametrize( "GradientBoosting, X, y", diff --git a/sklearn/linear_model/tests/test_sgd.py b/sklearn/linear_model/tests/test_sgd.py index d0c4020967d20..35fa08b894b06 100644 --- a/sklearn/linear_model/tests/test_sgd.py +++ b/sklearn/linear_model/tests/test_sgd.py @@ -250,7 +250,7 @@ def asgd(klass, X, y, eta, alpha, weight_init=None, intercept_init=0.0): ], # Avoid long error messages in test names: # https://github.com/scikit-learn/scikit-learn/issues/21362 - ids=lambda x: "error" if isinstance(x, str) and len(x) > 10 else x, + ids=lambda x: x[:10].replace("]", "") if isinstance(x, str) else x, ) def test_sgd_estimator_params_validation(klass, fit_method, params, err_msg): """Validate parameters in the different SGD estimators."""