Skip to content

TST replace pytest.warns(None) in test_label_propagation.py #23010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions sklearn/semi_supervised/tests/test_label_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import pytest
import warnings

from scipy.sparse import issparse
from sklearn.semi_supervised import _label_propagation as label_propagation
Expand Down Expand Up @@ -151,14 +152,14 @@ def test_convergence_warning():
assert mdl.n_iter_ == mdl.max_iter

mdl = label_propagation.LabelSpreading(kernel="rbf", max_iter=500)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error", ConvergenceWarning)
mdl.fit(X, y)
assert not [w.message for w in record]

mdl = label_propagation.LabelPropagation(kernel="rbf", max_iter=500)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error", ConvergenceWarning)
mdl.fit(X, y)
assert not [w.message for w in record]


@pytest.mark.parametrize(
Expand All @@ -173,9 +174,9 @@ def test_label_propagation_non_zero_normalizer(LabelPropagationCls):
X = np.array([[100.0, 100.0], [100.0, 100.0], [0.0, 0.0], [0.0, 0.0]])
y = np.array([0, 1, -1, -1])
mdl = LabelPropagationCls(kernel="knn", max_iter=100, n_neighbors=1)
with pytest.warns(None) as record:
with warnings.catch_warnings():
warnings.simplefilter("error", RuntimeWarning)
mdl.fit(X, y)
assert not [w.message for w in record]


def test_predict_sparse_callable_kernel():
Expand Down