From 8f1731cbc62fbcc325f8fedbb138438b3946f778 Mon Sep 17 00:00:00 2001 From: Tejas Date: Fri, 8 May 2026 23:11:53 -0400 Subject: [PATCH 1/2] Fixed flaky test_optional by using seed and larger sample size. --- tests/test_optional.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_optional.py b/tests/test_optional.py index f84bcdb3c5..b8a96baec6 100644 --- a/tests/test_optional.py +++ b/tests/test_optional.py @@ -6,8 +6,13 @@ class TestOptionalClass: def test_optional(self) -> None: fake = Faker() + Faker.seed(0) - assert {fake.optional.boolean() for _ in range(10)} == {True, False, None} + # 100 draws make it astronomically unlikely to miss any of the three + # outcomes (True, False, None) even under worst-case probability splits. + # 10 draws had a ~12% empirical failure rate (see GH-2366). + values = {fake.optional.boolean() for _ in range(100)} + assert values == {True, False, None} def test_optional_probability(self) -> None: """The probability is configurable.""" From 0ba32546e9975f2aecfec19b43947a0c1695e0a5 Mon Sep 17 00:00:00 2001 From: Tejas Date: Sun, 7 Jun 2026 11:48:33 -0400 Subject: [PATCH 2/2] Remove seed from test_optional; 100 draws are sufficient on their own Seeding made the test deterministic against a fixed sequence rather than verifying probabilistic coverage. 100 draws reduce failure probability to < 0.000003% without relying on a specific seed. Trims the 3-line comment to a single reference line. Co-Authored-By: Claude Sonnet 4.6 --- tests/test_optional.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_optional.py b/tests/test_optional.py index b8a96baec6..2abf3ba65b 100644 --- a/tests/test_optional.py +++ b/tests/test_optional.py @@ -6,11 +6,7 @@ class TestOptionalClass: def test_optional(self) -> None: fake = Faker() - Faker.seed(0) - - # 100 draws make it astronomically unlikely to miss any of the three - # outcomes (True, False, None) even under worst-case probability splits. - # 10 draws had a ~12% empirical failure rate (see GH-2366). + # 100 draws; 10 drew ~12% failure rate (GH-2366) values = {fake.optional.boolean() for _ in range(100)} assert values == {True, False, None}