Invalid examples in simple cases

21 views
Skip to first unread message

Jonathan Berthias

unread,
Dec 16, 2022, 10:46:56 AM12/16/22
to Hypothesis users
Hi,

I'm not sure if this was asked before (couldn't find it though), but I would like some details about what the invalid examples are.

I am running hypothesis with the pytest --hypothesis-show-statistics flag. the docs show this snippet:

@given(st.integers())
def test_integers(i):
     pass

which yields the following stats:

100 passing examples, 0 failing examples, 0 invalid examples

However, changing the `st.integers()` to `st.floats()` yields some invalid examples:

100 passing examples, 0 failing examples, 2 invalid examples

Could you explain why that is? I thought invalid examples were due to failing filters or assume statements, but it seems even plain data generation can create them.

Thanks,
Jonathan

Zac Hatfield Dodds

unread,
Dec 17, 2022, 4:35:39 PM12/17/22
to Jonathan Berthias, Hypothesis users
Hi Jonathan,

https://hypothesis.works/articles/how-hypothesis-works/ explains a bit about Hypothesis' underlying model of "parsing examples from choices" (usually random bytes).  

The invalid examples here are because the `st.floats()` strategy will sometimes try generating particularly weird examples from an internal list, and so it's possible to end up rejecting an example because it repeatedly tries to generate e.g. the fourth of three weird edge cases.  `st.integers()` will do the same thing, if you specify two endpoints!

Cheers,
Zac




--
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/6aa4fc1f-1ec8-4ebd-84bc-7c9a644f88c7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages