MNT Replace pytest.warns(None) in test_text.py
@@ -1357,13 +1357,13 @@ def test_tfidf_vectorizer_type(vectorizer_dtype, output_dtype, warning_expected)
vectorizer = TfidfVectorizer(dtype=vectorizer_dtype)
warning_msg_match = "'dtype' should be used."
- warning_cls = UserWarning
- expected_warning_cls = warning_cls if warning_expected else None
- with pytest.warns(expected_warning_cls, match=warning_msg_match) as record:
+ if warning_expected:
+ with pytest.warns(UserWarning, match=warning_msg_match):
+ X_idf = vectorizer.fit_transform(X)
+ else:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", UserWarning)
X_idf = vectorizer.fit_transform(X)
- if expected_warning_cls is None:
- relevant_warnings = [w for w in record if isinstance(w, warning_cls)]
- assert len(relevant_warnings) == 0
assert X_idf.dtype == output_dtype
