HypothesisWorks / hypothesis

Hypothesis is a powerful, flexible, and easy to use library for property-based testing.
https://hypothesis.works
Other
7.58k stars 587 forks source link

IndexError: list index out of range with integers strategy in Hypothesis 6.115.2 on Python 3.10.5 #4140

Closed HeikeGilg closed 1 month ago

HeikeGilg commented 1 month ago

Description:

I encountered an issue with the hypothesis package version 6.115.2 when running a test case that uses the @hypothesis.given decorator with an integers strategy. The error occurs specifically with Python 3.10.5 and does not manifest with Python 3.8 or older versions of hypothesis (e.g., 6.115.0).

Steps to Reproduce:

  1. Install hypothesis version 6.115.2.
  2. Use Python 3.10.5 to run the following test case:
import hypothesis

@hypothesis.given(size=hypothesis.strategies.integers(min_value=121, max_value=255))
@hypothesis.seed(5196489849994870713126665243569287741)  # Seed to reproduce the issue
def test(size):
    pass

test()
  1. Observe the traceback.

Expected Behavior:

The test should execute without errors, generating integers between 121 and 255.

Actual Behavior:

An IndexError: list index out of range is raised during execution. The traceback points to the choice method in random.py:

Traceback (most recent call last):
    ....
    File: "xxx/random.py", line 3789, in choice
         return seq[self._randbelow(len(seq))]
IndexError: list index out of range

Environment:

Additional Information:

The seed used for reproducing the issue is 5196489849994870713126665243569287741.

tybug commented 1 month ago

Thanks – regressed in #4138. Pretty embarrassing on my end. afk for the next few hours but will have a fix out today.