TST Replace pytest.warns(None) in tests/test_naive_bayes.py
@@ -3,6 +3,7 @@ import re
import numpy as np
import scipy.sparse
import pytest
+import warnings
from sklearn.datasets import load_digits, load_iris
@@ -513,18 +514,20 @@ def test_mnb_prior_unobserved_targets():
clf = MultinomialNB()
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", RuntimeWarning)
+
clf.partial_fit(X, y, classes=[0, 1, 2])
- assert not [w.message for w in record]
assert clf.predict([[0, 1]]) == 0
assert clf.predict([[1, 0]]) == 1
assert clf.predict([[1, 1]]) == 0
# add a training example with previously unobserved class
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", RuntimeWarning)
+
clf.partial_fit([[1, 1]], [2])
- assert not [w.message for w in record]
assert clf.predict([[0, 1]]) == 0
assert clf.predict([[1, 0]]) == 1
