TST replace pytest.warns(None) in test_coordinate_descent.py
import numpy as np
import pytest
+import warnings
from scipy import interpolate, sparse
from copy import deepcopy
import joblib
@@ -98,11 +99,11 @@ def test_assure_warning_when_normalize(CoordinateDescentModel, normalize, n_warn
y = np.stack((y, y), axis=1)
model = CoordinateDescentModel(normalize=normalize)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings(record=True) as rec:
+ warnings.simplefilter("always", FutureWarning)
model.fit(X, y)
- record = [r for r in record if r.category == FutureWarning]
- assert len(record) == n_warnings
+ assert len([w.message for w in rec]) == n_warnings
@pytest.mark.parametrize(
@@ -1427,12 +1428,11 @@ def test_convergence_warnings():
with pytest.warns(ConvergenceWarning):
MultiTaskElasticNet(max_iter=1, tol=-1).fit(X, y)
- # check that the model converges w/o warnings
- with pytest.warns(None) as record:
+ # check that the model converges w/o convergence warnings
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", ConvergenceWarning)
MultiTaskElasticNet().fit(X, y)
- assert not [w.message for w in record]
-
def test_sparse_input_convergence_warning():
X, y, _, _ = build_dataset(n_samples=1000, n_features=500)
@@ -1440,12 +1440,11 @@ def test_sparse_input_convergence_warning():
with pytest.warns(ConvergenceWarning):
ElasticNet(max_iter=1, tol=0).fit(sparse.csr_matrix(X, dtype=np.float32), y)
- # check that the model converges w/o warnings
- with pytest.warns(None) as record:
+ # check that the model converges w/o convergence warnings
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", ConvergenceWarning)
Lasso().fit(sparse.csr_matrix(X, dtype=np.float32), y)
- assert not [w.message for w in record]
-
@pytest.mark.parametrize(
"precompute, inner_precompute",
