TST Replace pytest.warns(None) in feature_extraction/tests/test_text.py
@@ -2,6 +2,7 @@ from collections.abc import Mapping
import re
import pytest
+import warnings
from scipy import sparse
from sklearn.feature_extraction.text import strip_tags
@@ -450,9 +451,9 @@ def test_countvectorizer_uppercase_in_vocab():
with pytest.warns(UserWarning, match=message):
vectorizer.fit(vocabulary)
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
vectorizer.transform(vocabulary)
- assert not [w.message for w in record]
def test_tf_transformer_feature_names_out():
@@ -1420,9 +1421,9 @@ def test_vectorizer_stop_words_inconsistent():
assert _check_stop_words_consistency(vec) is False
# Only one warning per stop list
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
vec.fit_transform(["hello world"])
- assert not [w.message for w in record]
assert _check_stop_words_consistency(vec) is None
# Test caching of inconsistency assessment
