-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Meta] Research: what can we test with Hypothesis? #107862
Comments
Right now I've ported and modified several |
I'd suggest looking at PyPy's property-based tests, since they're known to be useful for developers of a Python implementation. I'd also reconsider (3). While complicated strategies are obviously more work to develop and use, in my experience they're also disproportionately likely to find bugs - precisely because code working with complicated data structures are even more difficult to test without Hypothesis, and so there are usually weird edge cases. Examples of this effect include #84838, #86384, #89901, and #83134. The |
Personally, I don't think we should go down this path. Hypothesis has a certain amount of randomness to it. In general, our tests should be specifically designed to cover every path of interest. When someone is designing new code, it is perfectly reasonable to use Hypothesis. However, for existing code, we "let's use Hypothesis" isn't a goal directed as a specific problem. One issue that we've had with people pursuing a "let's use Hypothesis" goal is that they are rarely working on modules that they fully understand, that the invariants they mentally invent aren't the actual invariants and reflect bugs in their own understanding rather than actual bugs in the code. For example, we got reports on It would be perfectly reasonable to use Hypothesis outside of our test suite and then report an actual bug if found. Otherwise, I think actually checking in the h-tests would just garbage-up our test suite, make it run less deterministically, and no explicitly write-out all the cases being covered. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
But, we already have Hypothesis as a part of your test suite and CI. It already has some tests to it. Link: cpython/.github/workflows/build.yml Lines 361 to 467 in 5d936b6
I propose adding more cases, where it makes sense.
I agree that our regular tests should cover all paths, but there are more to it. Path coverage is only as good as 100%. But, we are obviously limited by the number of data we can provide. We cannot come up with lots of data, our current test suites proove my point. But, Hypothesis can. This is exactly what it is good at: proving lots of correctly structured data.
There are different way on how we control the randomness. First, we use a database with examples: cpython/Lib/test/support/hypothesis_helper.py Lines 22 to 35 in 5d936b6
This is a valid concern, I hope that collaboration among developers can solve this.
I don't think that this is actually correct. First, we cannot know what bugs were found by Hypothesis, because people might just post the simplest repro without naming the tool. Second, we have these bugs that do mention Hypothesis: Refs #86275 |
btw, I'm new to Hypothesis and the Edit: Thanks for all your kind warnings, I didn't actually try to use it. I just stared into the abyss and it stared back at me. It's fascinating in an academic sense. The way that some people read about https://en.wikipedia.org/wiki/Australian_funnel-web_spider |
I do think we should be expanding hypothesis tests. There was no stipulation in the original acceptance that they would only be used for zoneinfo, the idea was to use property tests more widely. We should at least start by migrating whichever tests in Zac's repo still make sense (probably most of them). Since they don't run on all CI, they should always come with |
We now have both the code and CI job to run
hypothesis
tests.In this issue I invite everyone to propose ideas: what can we test with it?
Criteria:
hypothesis
hypothesis
will produce a lot of cases to tests, we cannot do any slow / network related things)What else?
Known applications
Property-based tests are great when there are certain patterns:
decode
andencode
dumps
andloads
There are also some hidden patterns as (example):
'a' in s
thens.index('a')
must return an integerExisting work
Good examples of exising stuff:
hypothesis
tests intest_zoneinfo
by @pganssleLinked PRs
hypothesis
tests totest_binascii
#107863The text was updated successfully, but these errors were encountered: