MNT Replace pytest.warns(None) in test_ridge.py
@@ -4,6 +4,7 @@ from scipy import linalg
from itertools import product
import pytest
+import warnings
from sklearn.utils import _IS_32BIT
from sklearn.utils._testing import assert_almost_equal
@@ -1384,9 +1385,9 @@ def test_ridge_fit_intercept_sparse(solver):
dense_ridge = Ridge(solver="sparse_cg", tol=1e-12)
sparse_ridge = Ridge(solver=solver, tol=1e-12, positive=positive)
dense_ridge.fit(X, y)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
sparse_ridge.fit(X_csr, y)
- assert not [w.message for w in record]
assert np.allclose(dense_ridge.intercept_, sparse_ridge.intercept_)
assert np.allclose(dense_ridge.coef_, sparse_ridge.coef_)
@@ -1413,9 +1414,9 @@ def test_ridge_fit_intercept_sparse_sag():
dense_ridge = Ridge(**params)
sparse_ridge = Ridge(**params)
dense_ridge.fit(X, y)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
sparse_ridge.fit(X_csr, y)
- assert not [w.message for w in record]
assert np.allclose(dense_ridge.intercept_, sparse_ridge.intercept_, rtol=1e-4)
assert np.allclose(dense_ridge.coef_, sparse_ridge.coef_, rtol=1e-4)
with pytest.warns(UserWarning, match='"sag" solver requires.*'):
