TST replace pytest.warns(None) in test_function_transformer.py
+import warnings
+
import pytest
import numpy as np
from scipy import sparse
@@ -152,9 +154,10 @@ def test_check_inverse():
check_inverse=True,
validate=True,
)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
Xt = trans.fit_transform(X)
- assert not [w.message for w in record]
+
assert_allclose_dense_sparse(X, trans.inverse_transform(Xt))
# check that we don't check inverse when one of the func or inverse is not
@@ -162,15 +165,15 @@ def test_check_inverse():
trans = FunctionTransformer(
func=np.expm1, inverse_func=None, check_inverse=True, validate=True
)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
trans.fit(X_dense)
- assert not [w.message for w in record]
trans = FunctionTransformer(
func=None, inverse_func=np.expm1, check_inverse=True, validate=True
)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
trans.fit(X_dense)
- assert not [w.message for w in record]
def test_function_transformer_frame():
