Skip to content

Commit f781b3f

Browse files
committed
Merge branch 'master' into constants-speedup
2 parents e518108 + 48edfbf commit f781b3f

File tree

12 files changed

+734
-721
lines changed

12 files changed

+734
-721
lines changed

hypothesis-python/docs/changelog.rst

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ Hypothesis 6.x
1818

1919
.. include:: ../RELEASE.rst
2020

21+
.. _v6.131.5:
22+
23+
--------------------
24+
6.131.5 - 2025-04-18
25+
--------------------
26+
27+
Fix a rare case where database entries were kept after they were no longer needed when using |Phase.target|.
28+
29+
.. _v6.131.4:
30+
31+
--------------------
32+
6.131.4 - 2025-04-18
33+
--------------------
34+
35+
Internal refactoring of the |@settings| object, with no user-visible change.
36+
2137
.. _v6.131.3:
2238

2339
--------------------
@@ -336,7 +352,7 @@ Fix a type-hinting regression from :ref:`version 6.125.1 <v6.125.1>`, where we w
336352
6.127.6 - 2025-03-04
337353
--------------------
338354

339-
This patch tweaks the performance of the :ref:`target phase <phases>`, avoiding aborting some test cases when it would be better to finish generating them.
355+
This patch tweaks the performance of |Phase.target|, avoiding aborting some test cases when it would be better to finish generating them.
340356

341357
.. _v6.127.5:
342358

@@ -559,7 +575,7 @@ Improves one of our shrinking passes for integers which require a constant relat
559575
6.123.14 - 2025-01-11
560576
---------------------
561577

562-
Avoid realizing symbolic values from :ref:`alternative-backends` when :obj:`~hypothesis.settings.verbosity` is ``verbose`` or higher.
578+
Avoid realizing symbolic values from :ref:`alternative-backends` when |Verbosity| is ``verbose`` or higher.
563579

564580
.. _v6.123.13:
565581

@@ -800,7 +816,7 @@ This patch fixes a bug since :ref:`v6.99.13` where only interactively-generated
800816
6.119.3 - 2024-11-17
801817
--------------------
802818

803-
Hypothesis collects coverage information during the ``shrink`` and ``explain`` :ref:`phases <phases>` in order to show a more informative error message. On 3.12+, this uses :mod:`sys.monitoring`. This patch improves the performance of coverage collection on 3.12+ by disabling events we don't need.
819+
Hypothesis collects coverage information during the |Phase.shrink| and |Phase.explain| phases in order to show a more informative error message. On 3.12+, this uses :mod:`sys.monitoring`. This patch improves the performance of coverage collection on 3.12+ by disabling events we don't need.
804820

805821
.. _v6.119.2:
806822

@@ -893,7 +909,7 @@ This patch adds more type hints to internal Hypothesis code.
893909
6.118.2 - 2024-11-09
894910
--------------------
895911

896-
This patch migrates the :obj:`~hypothesis.Phase.explain` :ref:`phase <phases>` to our IR layer (:issue:`3921`). This should improve both its speed and precision.
912+
This patch migrates the |Phase.explain| phase to our IR layer (:issue:`3921`). This should improve both its speed and precision.
897913

898914
.. _v6.118.1:
899915

@@ -1957,7 +1973,7 @@ as well continue running the test!
19571973
Because we now finish running a few more examples for affected tests, this
19581974
might be a slight slowdown - but correspondingly more likely to find a bug.
19591975

1960-
We've also applied similar tricks to the :ref:`target phase <phases>`, where
1976+
We've also applied similar tricks to the |Phase.target| phase, where
19611977
they are a pure performance improvement for affected tests.
19621978

19631979
.. _v6.97.1:
@@ -2425,7 +2441,7 @@ one provided by an xfailed example.
24252441
6.86.0 - 2023-09-17
24262442
-------------------
24272443

2428-
This release enables the :obj:`~hypothesis.Phase.explain` :ref:`phase <phases>`
2444+
This release enables the |Phase.explain| phase
24292445
by default. We hope it helps you to understand *why* your failing tests have
24302446
failed!
24312447

@@ -2925,9 +2941,9 @@ with versions before 1.20, which were broken by a mistake in Hypothesis 6.72.4
29252941
6.73.0 - 2023-04-25
29262942
-------------------
29272943

2928-
This release upgrades the :ref:`explain phase <phases>` (:issue:`3411`).
2944+
This release upgrades the |Phase.explain| phase (:issue:`3411`).
29292945

2930-
* Following the first failure, Hypothesis will (:ref:`usually <phases>`) track which
2946+
* Following the first failure, Hypothesis will (usually, depending on the enabled |Phase|) track which
29312947
lines of code were executed by passing and failing examples, and report where they
29322948
diverged - with some heuristics to drop unhelpful reports. This is an existing
29332949
feature, now upgraded and newly enabled by default.
@@ -3461,7 +3477,7 @@ This patch updates our autoformatting tools, improving our code style without an
34613477
-------------------
34623478

34633479
This patch fixes some type annotations for Python 3.9 and earlier (:issue:`3397`),
3464-
and teaches :ref:`explain mode <phases>` about certain locations it should not
3480+
and teaches the |Phase.explain| phase about certain locations it should not
34653481
bother reporting (:issue:`3439`).
34663482

34673483
.. _v6.54.3:
@@ -4980,7 +4996,7 @@ There is no user-visible change.
49804996
6.14.0 - 2021-06-09
49814997
-------------------
49824998

4983-
The :ref:`explain phase <phases>` now requires shrinking to be enabled,
4999+
The |Phase.explain| phase now requires shrinking to be enabled,
49845000
and will be automatically skipped for deadline-exceeded errors.
49855001

49865002
.. _v6.13.14:
@@ -5413,7 +5429,7 @@ meant to be allowed (:issue:`2681`).
54135429
6.5.0 - 2021-03-07
54145430
------------------
54155431

5416-
This release adds :ref:`the explain phase <phases>`, in which Hypothesis
5432+
This release adds |Phase.explain|, in which Hypothesis
54175433
attempts to explain *why* your test failed by pointing to suspicious lines
54185434
of code (i.e. those which were always, and only, run on failing inputs).
54195435
We plan to include "generalising" failing examples in this phase in a
@@ -11849,7 +11865,7 @@ documentation, by explaining that example shrinking is tracked at the level
1184911865
of the underlying bytestream rather than the output value.
1185011866

1185111867
The output from ``find()`` in verbose mode has also been
11852-
adjusted - see :ref:`the example session <verbose-output>` - to avoid
11868+
adjusted - see the example session for |Verbosity| - to avoid
1185311869
duplicating lines when the example repr is constant, even if the underlying
1185411870
representation has been shrunken.
1185511871

@@ -13601,7 +13617,7 @@ Thanks to Alex Willmer for these.
1360113617
3.17.0 - 2017-08-07
1360213618
-------------------
1360313619

13604-
This release documents :ref:`the previously undocumented phases feature <phases>`,
13620+
This release documents the previously undocumented phases feature in |Phase|,
1360513621
making it part of the public API. It also updates how the example
1360613622
database is used. Principally:
1360713623

hypothesis-python/docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,15 @@ def setup(app):
194194
<hypothesis.HealthCheck.differing_executors>`
195195
.. |HealthCheck| replace:: :obj:`~hypothesis.HealthCheck`
196196
197+
.. |Phase| replace:: :obj:`Phase <hypothesis.Phase>`
197198
.. |Phase.explicit| replace:: :obj:`Phase.explicit <hypothesis.Phase.explicit>`
198199
.. |Phase.reuse| replace:: :obj:`Phase.reuse <hypothesis.Phase.reuse>`
199200
.. |Phase.generate| replace:: :obj:`Phase.generate <hypothesis.Phase.generate>`
200201
.. |Phase.target| replace:: :obj:`Phase.target <hypothesis.Phase.target>`
201202
.. |Phase.shrink| replace:: :obj:`Phase.shrink <hypothesis.Phase.shrink>`
202203
.. |Phase.explain| replace:: :obj:`Phase.explain <hypothesis.Phase.explain>`
203204
205+
.. |Verbosity| replace:: :obj:`~hypothesis.Verbosity`
204206
.. |Verbosity.verbose| replace:: :obj:`Verbosity.verbose <hypothesis.Verbosity.verbose>`
205207
.. |Verbosity.debug| replace:: :obj:`Verbosity.debug <hypothesis.Verbosity.debug>`
206208
.. |Verbosity.normal| replace:: :obj:`Verbosity.normal <hypothesis.Verbosity.normal>`
@@ -248,6 +250,8 @@ def setup(app):
248250
.. |strategy.map| replace:: :func:`.map() <hypothesis.strategies.SearchStrategy.map>`
249251
.. |strategy.map()| replace:: :func:`.map() <hypothesis.strategies.SearchStrategy.map>`
250252
253+
.. |@rule| replace:: :func:`@rule <hypothesis.stateful.rule>`
254+
251255
.. |@reproduce_failure| replace:: :func:`@reproduce_failure <hypothesis.reproduce_failure>`
252256
253257
.. |ExampleDatabase| replace:: :class:`~hypothesis.database.ExampleDatabase`

hypothesis-python/docs/reference/api.rst

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -256,116 +256,11 @@ Settings
256256
:members:
257257
:exclude-members: register_profile, get_profile, load_profile
258258

259-
.. _phases:
260-
261-
Controlling what runs
262-
~~~~~~~~~~~~~~~~~~~~~
263-
264-
Hypothesis divides tests into logically distinct phases.
265-
266-
- |Phase.explicit|: Running explicit examples from |@example|.
267-
- |Phase.reuse|: Running examples from the database which previously failed.
268-
- |Phase.generate|: Generating new random examples.
269-
- |Phase.target|: Mutating examples for :ref:`targeted property-based testing <targeted>`.
270-
271-
- Requires |Phase.generate|.
272-
273-
- |Phase.shrink|: Shrinking failing examples.
274-
- |Phase.explain|: Attempting to explain why a failure occurred.
275-
276-
- Requires |Phase.shrink|.
277-
278-
.. note::
279-
280-
The explain phase has two parts, each of which is best-effort - if Hypothesis can't
281-
find a useful explanation, we'll just print the minimal failing example.
282-
283-
Following the first failure, Hypothesis will (:ref:`usually <phases>`) track which
284-
lines of code are always run on failing but never on passing inputs. On 3.12+, this uses
285-
:mod:`sys.monitoring`, while 3.11 and earlier uses :func:`python:sys.settrace`. For python 3.11
286-
and earlier, we therefore automatically disable the explain phase on PyPy, or if you are using
287-
:pypi:`coverage` or a debugger. If there are no clearly suspicious lines of code,
288-
:pep:`we refuse the temptation to guess <20>`.
289-
290-
After shrinking to a minimal failing example, Hypothesis will try to find parts of
291-
the example -- e.g. separate args to :func:`@given() <hypothesis.given>` -- which
292-
can vary freely without changing the result of that minimal failing example.
293-
If the automated experiments run without finding a passing variation, we leave a
294-
comment in the final report:
295-
296-
.. code-block:: python
297-
298-
test_x_divided_by_y(
299-
x=0, # or any other generated value
300-
y=0,
301-
)
302-
303-
Just remember that the *lack* of an explanation sometimes just means that Hypothesis
304-
couldn't efficiently find one, not that no explanation (or simpler failing example)
305-
exists.
306-
307-
308-
The phases setting provides you with fine grained control over which of these run,
309-
with each phase corresponding to a value on the :class:`~hypothesis.Phase` enum:
310-
311259
.. autoclass:: hypothesis.Phase
312-
:members:
313-
314-
The phases argument accepts a collection with any subset of these. e.g.
315-
``settings(phases=[Phase.generate, Phase.shrink])`` will generate new examples
316-
and shrink them, but will not run explicit examples or reuse previous failures,
317-
while ``settings(phases=[Phase.explicit])`` will only run the explicit
318-
examples.
319-
320-
.. _verbose-output:
321-
322-
Seeing intermediate result
323-
~~~~~~~~~~~~~~~~~~~~~~~~~~
260+
:members:
324261

325262
.. autoclass:: hypothesis.Verbosity
326-
:members: quiet,normal,verbose,debug
327-
328-
.. documenting all members runs into https://stackoverflow.com/a/78657325
329-
.. and the fix there didn't work for me
330-
.. TODO python 3.13: remove this?
331-
332-
To see what's going on while Hypothesis runs your tests, you can turn
333-
up the verbosity setting.
334-
335-
.. code-block:: pycon
336-
337-
>>> from hypothesis import find, settings, Verbosity
338-
>>> from hypothesis.strategies import lists, integers
339-
>>> @given(lists(integers()))
340-
... @settings(verbosity=Verbosity.verbose)
341-
... def f(x):
342-
... assert not any(x)
343-
... f()
344-
Trying example: []
345-
Falsifying example: [-1198601713, -67, 116, -29578]
346-
Shrunk example to [-1198601713]
347-
Shrunk example to [-1198601600]
348-
Shrunk example to [-1191228800]
349-
Shrunk example to [-8421504]
350-
Shrunk example to [-32896]
351-
Shrunk example to [-128]
352-
Shrunk example to [64]
353-
Shrunk example to [32]
354-
Shrunk example to [16]
355-
Shrunk example to [8]
356-
Shrunk example to [4]
357-
Shrunk example to [3]
358-
Shrunk example to [2]
359-
Shrunk example to [1]
360-
[1]
361-
362-
The four levels are quiet, normal, verbose and debug. normal is the default,
363-
while in quiet mode Hypothesis will not print anything out, not even the final
364-
falsifying example. debug is basically verbose but a bit more so. You probably
365-
don't want it.
366-
367-
If you are using :pypi:`pytest`, you may also need to
368-
:doc:`disable output capturing for passing tests <pytest:how-to/capture-stdout-stderr>`.
263+
:members:
369264

370265
Building settings objects
371266
~~~~~~~~~~~~~~~~~~~~~~~~~

hypothesis-python/docs/reference/integrations.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ is to let you answer questions you didn't think of in advance. In slogan form,
9797
*Debugging should be a data analysis problem.*
9898

9999
By default, Hypothesis only reports the minimal failing example... but sometimes you might
100-
want to know something about *all* the examples. Printing them to the terminal with
101-
:ref:`verbose output <verbose-output>` might be nice, but isn't always enough.
100+
want to know something about *all* the examples. Printing them to the terminal by increasing
101+
|Verbosity| might be nice, but isn't always enough.
102102
This feature gives you an analysis-ready dataframe with useful columns and one row
103103
per test case, with columns from arguments to code coverage to pass/fail status.
104104

@@ -171,9 +171,9 @@ Hypothesis includes a tiny plugin to improve integration with :pypi:`pytest`, wh
171171

172172
- ``pytest --hypothesis-show-statistics`` can be used to :ref:`display test and data generation statistics <statistics>`.
173173
- ``pytest --hypothesis-profile=<profile name>`` can be used to :ref:`load a settings profile <settings_profiles>`.
174-
- ``pytest --hypothesis-verbosity=<level name>`` can be used to :ref:`override the current verbosity level <verbose-output>`.
174+
- ``pytest --hypothesis-verbosity=<level name>`` can be used to override the current |Verbosity| setting.
175175
- ``pytest --hypothesis-seed=<an int>`` can be used to :ref:`reproduce a failure with a particular seed <reproducing-with-seed>`.
176-
- ``pytest --hypothesis-explain`` can be used to :ref:`temporarily enable the explain phase <phases>`.
176+
- ``pytest --hypothesis-explain`` can be used to temporarily enable |Phase.explain|.
177177

178178
Finally, all tests that are defined with Hypothesis automatically have ``@pytest.mark.hypothesis`` applied to them. See :ref:`here for information on working with markers <pytest:mark examples>`.
179179

0 commit comments

Comments
 (0)