Skip to content

Commit c58320f

Browse files
authored
[python-package] Add specific error messages to test_sklearn (#6929)
add error messages to test_sklearn.py
1 parent 59f8a9b commit c58320f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/python_package_test/test_sklearn.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,8 @@ def test_check_is_fitted():
15241524
rnk = lgb.LGBMRanker(n_estimators=5)
15251525
models = (est, clf, reg, rnk)
15261526
for model in models:
1527-
with pytest.raises(lgb.compat.LGBMNotFittedError):
1527+
err_msg = f"This {type(model).__name__} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
1528+
with pytest.raises(lgb.compat.LGBMNotFittedError, match=err_msg):
15281529
check_is_fitted(model)
15291530
est.fit(X, y)
15301531
clf.fit(X, y)
@@ -1623,7 +1624,8 @@ def test_getting_feature_names_in_np_input(estimator_class):
16231624
model = estimator_class(**{**params, "objective": "binary"})
16241625
else:
16251626
model = estimator_class(**params)
1626-
with pytest.raises(lgb.compat.LGBMNotFittedError):
1627+
err_msg = f"This {estimator_class.__name__} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
1628+
with pytest.raises(lgb.compat.LGBMNotFittedError, match=err_msg):
16271629
check_is_fitted(model)
16281630
if isinstance(model, lgb.LGBMRanker):
16291631
model.fit(X, y, group=[X.shape[0]])
@@ -1644,7 +1646,8 @@ def test_getting_feature_names_in_pd_input(estimator_class):
16441646
model = estimator_class(**{**params, "objective": "binary"})
16451647
else:
16461648
model = estimator_class(**params)
1647-
with pytest.raises(lgb.compat.LGBMNotFittedError):
1649+
err_msg = f"This {estimator_class.__name__} instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
1650+
with pytest.raises(lgb.compat.LGBMNotFittedError, match=err_msg):
16481651
check_is_fitted(model)
16491652
if isinstance(model, lgb.LGBMRanker):
16501653
model.fit(X, y, group=[X.shape[0]])

0 commit comments

Comments
 (0)