Repository: aesara-devs/aeppl (language: python)

Issue:
Set `filterwarnings` to `error` in the tests
Our tests should not allow un-caught/checked warnings.

The addition to `setup.cfg` mentioned [here](https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html) should be sufficient.  We'll need to update our tests to prevent them from failing, though.



Discussion / hints:

Fix patch:
diff --git a/setup.cfg b/setup.cfg
index 0c3e0bf1..d17af617 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -16,6 +16,9 @@ convention = numpy
 [tool:pytest]
 python_files=test*.py
 testpaths=tests
+filterwarnings =
+    error
+    ignore:::numdifftools
 
 [coverage:run]
 omit =


Test patch:
diff --git a/tests/test_cumsum.py b/tests/test_cumsum.py
index dac5e1ad..1c676aea 100644
--- a/tests/test_cumsum.py
+++ b/tests/test_cumsum.py
@@ -57,7 +57,7 @@ def test_bernoulli_cumsum(size, axis):
 def test_destructive_cumsum_fails():
     """Test that a cumsum that mixes dimensions fails"""
     x_rv = at.random.normal(size=(2, 2, 2)).cumsum()
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(x_rv)
 
 
diff --git a/tests/test_logprob.py b/tests/test_logprob.py
index 1c45fff8..2da4abb6 100644
--- a/tests/test_logprob.py
+++ b/tests/test_logprob.py
@@ -497,8 +497,11 @@ def test_vonmises_logprob(dist_params, obs, size, error):
     def scipy_logprob(obs, mu, kappa):
         return stats.vonmises.logpdf(obs, kappa, loc=mu)
 
-    with cm:
-        scipy_logprob_tester(x, obs, dist_params, test_fn=scipy_logprob)
+    with pytest.raises(
+        UserWarning, match="The Op i0 does not provide a C implementation"
+    ):
+        with cm:
+            scipy_logprob_tester(x, obs, dist_params, test_fn=scipy_logprob)
 
 
 @pytest.mark.parametrize(
diff --git a/tests/test_mixture.py b/tests/test_mixture.py
index 2a29be5c..a38d5ae1 100644
--- a/tests/test_mixture.py
+++ b/tests/test_mixture.py
@@ -42,8 +42,8 @@ def create_mix_model(size, axis):
     M_rv = env["M_rv"]
 
     with pytest.raises(
-        RuntimeError,
-        match="The logprob terms of the following random variables could not be derived: {M}",
+        UserWarning,
+        match="Found a random variable that is not",
     ):
         conditional_logprob(M_rv, I_rv, X_rv)
 
diff --git a/tests/test_tensor.py b/tests/test_tensor.py
index c5cd39c7..2f0e9ee0 100644
--- a/tests/test_tensor.py
+++ b/tests/test_tensor.py
@@ -265,5 +265,5 @@ def test_unmeargeable_dimshuffles():
     w = z.dimshuffle((1, 0, 2))
 
     # TODO: Check that logp is correct if this type of graphs is ever supported
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(w)
diff --git a/tests/test_transforms.py b/tests/test_transforms.py
index efd7688a..db75eabd 100644
--- a/tests/test_transforms.py
+++ b/tests/test_transforms.py
@@ -463,16 +463,12 @@ def test_mixture_transform():
 
     transform_rewrite = TransformValuesRewrite({Y_rv: LogOddsTransform()})
 
-    with pytest.warns(None) as record:
-        # This shouldn't raise any warnings
-        logp_trans, (y_vv_trans, i_vv_trans) = joint_logprob(
-            Y_rv,
-            I_rv,
-            extra_rewrites=transform_rewrite,
-            use_jacobian=False,
-        )
-
-    assert not record.list
+    logp_trans, (y_vv_trans, i_vv_trans) = joint_logprob(
+        Y_rv,
+        I_rv,
+        extra_rewrites=transform_rewrite,
+        use_jacobian=False,
+    )
 
     logp_fn = aesara.function((i_vv, y_vv), logp)
     logp_trans_fn = aesara.function((i_vv_trans, y_vv_trans), logp_trans)
@@ -588,8 +584,8 @@ def test_loc_transform_rv(rv_size, loc_type):
     assert_no_rvs(logp)
     logp_fn = aesara.function([loc, y_vv], logp)
 
-    loc_test_val = np.full(rv_size, 4.0)
-    y_test_val = np.full(rv_size, 1.0)
+    loc_test_val = np.full(rv_size or (), 4.0)
+    y_test_val = np.full(rv_size or (), 1.0)
 
     np.testing.assert_allclose(
         logp_fn(loc_test_val, y_test_val),
@@ -616,8 +612,8 @@ def test_scale_transform_rv(rv_size, scale_type):
     assert_no_rvs(logp)
     logp_fn = aesara.function([scale, y_vv], logp)
 
-    scale_test_val = np.full(rv_size, 4.0)
-    y_test_val = np.full(rv_size, 1.0)
+    scale_test_val = np.full(rv_size or (), 4.0)
+    y_test_val = np.full(rv_size or (), 1.0)
 
     np.testing.assert_allclose(
         logp_fn(scale_test_val, y_test_val),
@@ -648,7 +644,7 @@ def test_loc_transform_multiple_rvs_fails1():
     x_rv2 = at.random.normal(name="x_rv2")
     y_rv = x_rv1 + x_rv2
 
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(y_rv)
 
 
@@ -657,19 +653,19 @@ def test_nested_loc_transform_multiple_rvs_fails2():
     x_rv2 = at.cos(at.random.normal(name="x_rv2"))
     y_rv = x_rv1 + x_rv2
 
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(y_rv)
 
 
 def test_discrete_rv_unary_transform_fails():
     y_rv = at.exp(at.random.poisson(1))
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(y_rv)
 
 
 def test_discrete_rv_multinary_transform_fails():
     y_rv = 5 + at.random.poisson(1)
-    with pytest.raises(RuntimeError, match="could not be derived"):
+    with pytest.raises(UserWarning, match="Found a random variable that is not"):
         joint_logprob(y_rv)