-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Deep integration between Hypothesis and py.test is currently impossible #916
Copy link
Copy link
Open
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogmight present some backward compatibility issues which should be carefully noted in the changelogtype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branch
Metadata
Metadata
Assignees
Labels
topic: collectionrelated to the collection phaserelated to the collection phasetopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: backward compatibilitymight present some backward compatibility issues which should be carefully noted in the changelogmight present some backward compatibility issues which should be carefully noted in the changelogtype: enhancementnew feature or API change, should be merged into features branchnew feature or API change, should be merged into features branch
Context: I write Hypothesis, a randomized testing library for Python. It works "well" under py.test, but only in the sense that it ignores py.test almost completely other than doing its best to expose functions in a way that py.test fixtures can understand.
A major problem with using Hypothesis with py.test is that function level fixtures get evaluated once per top-level function, not once per example. When these fixtures are mutable and mutated by the test this is really bad, because you end up running the test against the fixture many times, changing it each time.
People keep running into this as an issue, but currently it seems to be impossible to fix without significant changes to py.test. @RonnyPfannschmidt asked me to write a ticket about this as an example use-case of subtests, so here I am.
So what's the problem?
A test using Hypothesis looks something like:
This translates into something approximately like:
The key problem here is that examples() cannot be evaluated at collect time because it depends on the results of previous test execution.
The reasons of this in order of decreasing amount of "this seems to be impossible" (i.e. with the current feature set of py.test I have no idea how to solve the first and neither does anyone else, could maybe solve the second, could definitely do something about the third):