We have found that this pattern to test for warnings being raised was too fragile, and we use sklearn.utils.assert_warns.