8000 TST Use pytest.raises instead of legacy constructions (#12057) · scikit-learn/scikit-learn@ec69171 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec69171

Browse files
rthjorisvandenbossche
authored andcommitted
TST Use pytest.raises instead of legacy constructions (#12057)
1 parent e36254c commit ec69171

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

sklearn/ensemble/tests/test_voting_classifier.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,14 @@ def test_predict_proba_on_toy_problem():
203203
assert_almost_equal(t21, eclf_res[2][1], decimal=1)
204204
assert_almost_equal(t31, eclf_res[3][1], decimal=1)
205205

206-
try:
206+
with pytest.raises(
207+
AttributeError,
208+
match="predict_proba is not available when voting='hard'"):
207209
eclf = VotingClassifier(estimators=[
208210
('lr', clf1), ('rf', clf2), ('gnb', clf3)],
209211
voting='hard')
210212
eclf.fit(X, y).predict_proba(X)
211213

212-
except AttributeError:
213-
pass
214-
else:
215-
raise AssertionError('AttributeError for voting == "hard"'
216-
' and with predict_proba not raised')
217-
218214

219215
def test_multilabel():
220216
"""Check if error is raised for multilabel classification."""

sklearn/model_selection/tests/test_split.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,10 @@ def test_shuffle_kfold_stratifiedkfold_reproducibility():
482482
cv.split(*data)):
483483
# cv.split(...) returns an array of tuples, each tuple
484484
# consisting of an array with train indices and test indices
485-
try:
485+
with pytest.raises(AssertionError,
486+
message="The splits for data, are same even"
487+
" when random state is not set"):
486488
np.testing.assert_array_equal(test_a, test_b)
487-
except AssertionError:
488-
pass
489-
else:
490-
raise AssertionError("The splits for data, are same even "
491-
"when random state is not set")
492489

493490

494491
def test_shuffle_stratifiedkfold():

0 commit comments

Comments
 (0)
0