diff --git a/testing/pytest/test_employee_pytest.py b/testing/pytest/test_employee_pytest.py index b08f2cf..0c590a3 100644 --- a/testing/pytest/test_employee_pytest.py +++ b/testing/pytest/test_employee_pytest.py @@ -3,6 +3,11 @@ import pytest from employee import Employee +# seeded at import time so parametrize decorator gets deterministic values (avoid ) +# without seed, random.randint() produces different values each run (flaky tests) +_rng = random.Random(42) +_random_test_cases = [(_rng.randint(0, 100),) * 2 for _ in range(9)] + # pytest doesn't require TestCase to inherit from anything class EmployeeTestCase: @@ -40,15 +45,7 @@ def test_pay(employee): (100, 100), (1999, 1999), (2022, 2022), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), - tuple([random.randint(0, 100)] * 2), + *_random_test_cases, ], ) def test_very_simple(given_value, expected_value):