Shrinking a given example

26 views
Skip to first unread message

Nicholas Chammas

unread,
Jan 14, 2024, 8:40:08 PMJan 14
to Hypothesis users
A user reported a bug in a function and provided a reproduction. I decided to write a test for this function to see if Hypothesis could find the same bug.

The test looks like this:

@given(data=lists(tuples(floats())))
def test_percentile(data):
    ...

I’ve run this test with up to 100,000 examples, but Hypothesis is not finding this bug. A very specific set of circumstances that I do not understand need to line up precisely for this bug to reveal itself.

I am now trying to figure out something different: Given a known failing example, can Hypothesis help me shrink it to its simplest form?

The reproduction provided by the user is a list that’s 373 elements long. I managed to manually shrink it down to 45 elements.

Is there any way to get Hypothesis to shrink the known failing example even further?

Zac Hatfield Dodds

unread,
Jan 15, 2024, 3:24:01 AMJan 15
to Nicholas Chammas, Hypothesis users
Great question!  This comes up often enough that I've cross-posted and answered it at https://stackoverflow.com/a/77818444/9297601 - unfortunately the short version is "no, Hypothesis can only shrink examples it generated", but using `hypothesis.target()` might make it easier to (re)generate a known failing example.

--
You received this message because you are subscribed to the Google Groups "Hypothesis users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hypothesis-use...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hypothesis-users/b8725d22-c501-4ddb-8af1-29be3f99494dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages