Skip to content

Commit b05d99c

Browse files
committed
Fix Potential flaky test: truncation_discrete_random
#6206 * Add seed to rejection test * Add a comment about the test probability
1 parent 7503730 commit b05d99c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pymc/tests/distributions/test_truncated.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ def test_truncation_discrete_random(op_type, lower, upper):
181181
assert np.any(xt_draws == upper)
182182
else:
183183
with pytest.raises(TruncationError, match="^Truncation did not converge"):
184-
draw(xt)
184+
# Rejections sampling with probability = (1 - p ** max_n_steps) ** sample_size =
185+
# = (1 - 0.2 ** 3) ** 500 = 0.018
186+
# Still, this probability can be too high to make this test pass with any seed.
187+
random_seed = 2297228
188+
draw(xt, random_seed=np.random.RandomState(random_seed))
185189

186190

187191
@pytest.mark.parametrize("lower, upper", [(2, np.inf), (2, 5), (-np.inf, 5)])

0 commit comments

Comments
 (0)