Skip to content

Commit 3b62f12

Browse files
committed
address review
1 parent 1387fe9 commit 3b62f12

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RELEASE_TYPE: patch
22

3-
Add ``PrimitiveProvider.replay_choices`` to the :ref:`alternative backends <alternative-backends>` interface.
3+
Add ``PrimitiveProvider.replay_choices`` to the :ref:`alternative backends <alternative-backends>` interface, to support warm-starting e.g. :pypi:`hypothesis-crosshair` from :pypi:`hypofuzz`.

hypothesis-python/src/hypothesis/internal/conjecture/providers.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ def draw_bytes(
367367
raise NotImplementedError
368368

369369
def per_test_case_context_manager(self):
370+
"""
371+
Returns a context manager which will be entered each time Hypothesis
372+
starts generating and executing one test case, and exited when that test
373+
case finishes generating and executing, including if any exception is
374+
thrown.
375+
376+
In the lifecycle of a Hypothesis test, this is called before
377+
generating strategy values for each test case. This is just before any
378+
:ref:`custom executor <custom-function-execution>` is called.
379+
380+
Even if not returning a custom context manager, PrimitiveProvider
381+
subclasses are welcome to override this method to know when Hypothesis
382+
starts and ends the execution of a single test case.
383+
"""
370384
return contextlib.nullcontext()
371385

372386
def realize(self, value: T, *, for_failure: bool = False) -> T:
@@ -390,17 +404,12 @@ def realize(self, value: T, *, for_failure: bool = False) -> T:
390404

391405
def replay_choices(self, choices: tuple[ChoiceT, ...]) -> None:
392406
"""
393-
Called to indicate that the provider should replay this choice sequence
394-
the next time Hypothesis enters per_test_case_context_manager, instead of
395-
generating its own choice sequence.
396-
397-
This is intended to indicate that the passed choice sequence is particularly
398-
interesting in some way, and that the provider should collect runtime
399-
information about it while replaying, in order to generate more effective
400-
choice sequences in the future.
407+
Called when Hypothesis has discovered a choice sequence which the provider
408+
may wish to enqueue to replay under its own instrumentation when we next
409+
ask to generate a test case, rather than generating one from scratch.
401410
402-
This method is currently used for relatively tight integration between
403-
Hypothesis and specific providers.
411+
This is used to e.g. warm-start hypothesis-crosshair with a corpus of
412+
high-code-coverage inputs discovered by HypoFuzz.
404413
"""
405414
return None
406415

0 commit comments

Comments
 (0)