TST replace pytest.warns(None) in metrics/cluster/test_unsupervised.py
+import warnings
+
import numpy as np
import scipy.sparse as sp
import pytest
@@ -341,14 +343,9 @@ def test_davies_bouldin_score():
pytest.approx(davies_bouldin_score(X, labels), 2 * np.sqrt(0.5) / 3)
# Ensure divide by zero warning is not raised in general case
- with pytest.warns(None) as record:
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", RuntimeWarning)
davies_bouldin_score(X, labels)
- div_zero_warnings = [
- warning
- for warning in record
- if "divide by zero encountered" in warning.message.args[0]
- ]
- assert len(div_zero_warnings) == 0
# General case - cluster have one sample
X = [[0, 0], [2, 2], [3, 3], [5, 5]]
