Skip to content

Commit e9d6049

Browse files
committed
Merge branch 'master' into next
2 parents 4052c28 + 513be56 commit e9d6049

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+799
-281
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ jobs:
244244
NODE_VERSION: 22
245245
# Note that the versions below are updated by `update_pyodide_versions()` in our weekly cronjob.
246246
# The versions of pyodide-build and the Pyodide runtime may differ.
247-
PYODIDE_VERSION: 0.28.1
248-
PYODIDE_BUILD_VERSION: 0.30.6
247+
PYODIDE_VERSION: 0.28.2
248+
PYODIDE_BUILD_VERSION: 0.30.7
249249
PYTHON_VERSION: 3.13.2
250250
steps:
251251
- uses: actions/checkout@v3

CONTRIBUTING.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ All of it will be checked on CI so you don't *have* to run anything locally, but
167167
find it useful to do so: A full CI run can take up to twenty minutes,
168168
so running a smaller set of tests locally can be helpful.
169169

170-
The build system should be "fairly" portable, but is currently only known to work on Linux or OS X. It *might* work
170+
The build system should be "fairly" portable, but is currently only known to work on Linux or macOS. It *might* work
171171
on a BSD or on Windows with cygwin installed, but it hasn't been tried. Windows with WSL does work,
172172
as for Linux, and since OS-specific issues are rare for Hypothesis that's pretty useful.
173173
If you try it and find it doesn't work, please do submit patches to fix that.
@@ -240,5 +240,3 @@ Some useful arguments to pytest include:
240240
e.g. ``-k'foo and not bar'`` will run anything containing foo that doesn't
241241
also contain bar. `More information on how to select tests to run can be found
242242
in the pytest documentation <https://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests>`__.
243-
244-

hypothesis-python/docs/changelog.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,56 @@ Hypothesis 6.x
1818

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

21+
.. _v6.138.7:
22+
23+
--------------------
24+
6.138.7 - 2025-08-28
25+
--------------------
26+
27+
Improves upon the cache eviction problem workaround
28+
of :v:`6.135.12`.
29+
30+
.. _v6.138.6:
31+
32+
--------------------
33+
6.138.6 - 2025-08-27
34+
--------------------
35+
36+
Documentation tweaks.
37+
38+
.. _v6.138.5:
39+
40+
--------------------
41+
6.138.5 - 2025-08-27
42+
--------------------
43+
44+
Fixes a race condition under threading for strategies which trigger our filter-rewriting rules, like ``st.integers().filter(lambda x: abs(x) > 100)``.
45+
46+
.. _v6.138.4:
47+
48+
--------------------
49+
6.138.4 - 2025-08-27
50+
--------------------
51+
52+
One of our shrinking passes for reducing failing inputs targets failures which require two numbers to add to the same value. This pass previously only worked for positive numbers. This patch fixes that, so it also works for negative numbers.
53+
54+
.. _v6.138.3:
55+
56+
--------------------
57+
6.138.3 - 2025-08-24
58+
--------------------
59+
60+
This patch slightly improves the cache-hit rate for
61+
|st.dictionaries| and certain unique |st.lists|.
62+
63+
.. _v6.138.2:
64+
65+
--------------------
66+
6.138.2 - 2025-08-16
67+
--------------------
68+
69+
The type annotations for |st.register_type_strategy| now indicate that it accepts registering types created with |TypeAliasType| (aka ``type MyType = int``).
70+
2171
.. _v6.138.1:
2272

2373
--------------------

hypothesis-python/docs/compatibility.rst

Lines changed: 71 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
Compatibility
22
=============
33

4-
Hypothesis does its level best to be compatible with everything you could
5-
possibly need it to be compatible with. Generally you should just try it and
6-
expect it to work. If it doesn't, you can be surprised and check this document
7-
for the details.
4+
Hypothesis generally does its level best to be compatible with everything you could need it to be compatible with. This document outlines our compatibility status and guarantees.
85

96
Hypothesis versions
107
-------------------
@@ -14,7 +11,7 @@ Backwards compatibility is better than backporting fixes, so we use
1411
version of Hypothesis.
1512

1613
Documented APIs will not break except between major version bumps.
17-
All APIs mentioned in this documentation are public unless explicitly
14+
All APIs mentioned in the Hypothesis documentation are public unless explicitly
1815
noted as provisional, in which case they may be changed in minor releases.
1916
Undocumented attributes, modules, and behaviour may include breaking
2017
changes in patch releases.
@@ -25,80 +22,94 @@ changes in patch releases.
2522
Deprecations
2623
------------
2724

28-
Deprecated features will emit warnings for at least six
29-
months, and then be removed in the following major release.
25+
Deprecated features will emit |HypothesisDeprecationWarning| for at least six months, and then be removed in the following major release.
3026

31-
Note however that not all warnings are subject to this grace period;
32-
sometimes we strengthen validation by adding a warning and these may
33-
become errors immediately at a major release.
34-
35-
We use custom exception and warning types, so you can see
36-
exactly where an error came from, or turn only our warnings into errors.
37-
38-
.. autoclass:: hypothesis.errors.HypothesisDeprecationWarning
27+
Note however that not all warnings are subject to this grace period; sometimes we strengthen validation by adding a warning, and these may become errors immediately at a major release.
3928

29+
We use custom exception and warning types, so you can see exactly where an error came from, or turn only our warnings into errors.
4030

4131
Python versions
4232
---------------
4333

44-
Hypothesis is supported and tested on CPython 3.9+, i.e.
45-
`all versions of CPython with upstream support <https://devguide.python.org/versions/>`_,
46-
along with PyPy for the same versions.
34+
Hypothesis is supported and tested on CPython and PyPy 3.9+, i.e. all Python versions `that are still supported <https://devguide.python.org/versions/>`_.
4735
32-bit builds of CPython also work, though we only test them on Windows.
4836

49-
In general Hypothesis does not officially support anything except the latest
50-
patch release of any version of Python it supports. Earlier releases should work
51-
and bugs in them will get fixed if reported, but they're not tested in CI and
52-
no guarantees are made.
37+
Hypothesis does not officially support anything except the latest patch release of each supported Python version. We will fix bugs in earlier patch releases if reported, but they're not tested in CI and no guarantees are made.
5338

5439
Operating systems
5540
-----------------
5641

57-
In theory Hypothesis should work anywhere that Python does. In practice it is
58-
only known to work and regularly tested on OS X, Windows and Linux, and you may
59-
experience issues running it elsewhere.
42+
In theory, Hypothesis should work anywhere that Python does. In practice, it is
43+
known to work and regularly tested on macOS, Windows, Linux, and `Emscripten <https://peps.python.org/pep-0776/>`_.
6044

61-
If you're using something else and it doesn't work, do get in touch and I'll try
62-
to help, but unless you can come up with a way for me to run a CI server on that
63-
operating system it probably won't stay fixed due to the inevitable march of time.
45+
If you experience issues running Hypothesis on other operating systems, we are
46+
happy to accept bug reports which either clearly point to the problem or contain
47+
reproducing instructions for a Hypothesis maintainer who does not have the ability
48+
to run that OS. It's hard to fix something we can't reproduce!
6449

6550
.. _framework-compatibility:
6651

6752
Testing frameworks
6853
------------------
6954

70-
In general Hypothesis goes to quite a lot of effort to generate things that
71-
look like normal Python test functions that behave as closely to the originals
72-
as possible, so it should work sensibly out of the box with every test framework.
73-
74-
If your testing relies on doing something other than calling a function and seeing
75-
if it raises an exception then it probably *won't* work out of the box. In particular
76-
things like tests which return generators and expect you to do something with them
77-
(e.g. nose's yield based tests) will not work. Use a decorator or similar to wrap the
78-
test to take this form, or ask the framework maintainer to support our
79-
:ref:`hooks for inserting such a wrapper later <custom-function-execution>`.
80-
81-
In terms of what's actually *known* to work:
82-
83-
* Hypothesis integrates as smoothly with pytest and unittest as we can make it,
84-
and this is verified as part of the CI.
85-
* :pypi:`pytest` fixtures work in the usual way for tests that have been decorated
86-
with |@given| - just avoid passing a strategy for
87-
each argument that will be supplied by a fixture. However, function-scoped fixtures
88-
will run only once for the whole function, not per example. To proactively warn you about
89-
this case, we raise |HealthCheck.function_scoped_fixture|, unless suppressed with
90-
|settings.suppress_health_check|.
91-
* The :func:`python:unittest.mock.patch` decorator works with
92-
|@given|, but we recommend using it as a context
93-
manager within the decorated test to ensure that the mock is per-test-case
94-
and avoid poor interactions with Pytest fixtures.
95-
* Nose works fine with Hypothesis, and this is tested as part of the CI. ``yield`` based
96-
tests simply won't work.
97-
* Integration with Django's testing requires use of the :ref:`hypothesis-django` extra.
98-
The issue is that in Django's tests' normal mode of execution it will reset the
99-
database once per test rather than once per example, which is not what you want.
100-
* :pypi:`coverage` works out of the box with Hypothesis; our own test suite has
101-
100% branch coverage.
55+
In general, Hypothesis goes to quite a lot of effort to return a function from |@given| that behaves as closely to a normal test function as possible. This means that most things should work sensibly with most testing frameworks.
56+
57+
Maintainers of testing frameworks may be interested in our support for :ref:`custom function execution <custom-function-execution>`, which may make some Hypothesis interactions possible to support.
58+
59+
pytest
60+
~~~~~~
61+
62+
The main interaction to be aware of between Hypothesis and :pypi:`pytest` is fixtures.
63+
64+
pytest fixtures are automatically passed to |@given| tests, as usual. Note that |@given| supplies parameters from the right, so tests which use a fixture should either be written with the fixture placed first, or with keyword arguments:
65+
66+
.. code-block:: python
67+
68+
@given(st.integers())
69+
def test_use_fixture(myfixture, n):
70+
pass
71+
72+
@given(n=st.integers())
73+
def test_use_fixture(n, myfixture):
74+
pass
75+
76+
However, function-scoped fixtures run only once for the entire test, not per-input. This can be surprising for fixtures which are expected to set up per-input state. To proactively warn about this, we raise |HealthCheck.function_scoped_fixture| (unless suppressed with |settings.suppress_health_check|).
77+
78+
Combining |@given| and |pytest.mark.parametrize| is fully supported, again keeping in mind that |@given| supplies parameters from the right:
79+
80+
.. code-block:: python
81+
82+
@pytest.mark.parametrize("s", ["a", "b", "c"])
83+
@given(st.integers())
84+
def test_use_parametrize(s, n):
85+
assert isinstance(s, str)
86+
assert isinstance(n, int)
87+
88+
unittest
89+
~~~~~~~~
90+
91+
:pypi:`unittest` works out of the box with Hypothesis.
92+
93+
The :func:`python:unittest.mock.patch` decorator works with |@given|, but we recommend using it as a context manager within the test instead, to ensure that the mock is per-input, and to avoid poor interactions with Pytest fixtures.
94+
95+
:meth:`unittest.TestCase.subTest` is a no-op under Hypothesis, because it interacts poorly with Hypothesis generating hundreds of inputs at a time.
96+
97+
Django
98+
~~~~~~
99+
100+
Integration with Django's testing requires use of the :ref:`hypothesis-django` extra. The issue is that Django tests reset the database once per test, rather than once per input.
101+
102+
:pypi:`pytest-django` doesn't yet implement Hypothesis compatibility. You can follow issue `pytest-django#912 <https://github.com/pytest-dev/pytest-django/issues/912>`_ for updates.
103+
104+
coverage.py
105+
~~~~~~~~~~~
106+
107+
:pypi:`coverage` works out of the box with Hypothesis. Our own test suite has 100% branch coverage.
108+
109+
HypoFuzz
110+
~~~~~~~~
111+
112+
`HypoFuzz <https://hypofuzz.com/>`_ is built on top of Hypothesis and has native support for it. See also the ``hypofuzz`` |alternative backend|.
102113

103114
Optional packages
104115
-----------------

hypothesis-python/docs/explanation/domain.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@ Domain and distribution
33

44
.. note::
55

6-
This page is mainly for users who are familiar with other property-based testing libraries, and who expect a way to control the distribution of inputs in Hypothesis, via e.g. a scale parameter for size or a frequency parameter for relative probabilities.
6+
This page is primarily for users who may be familiar with other property-based testing libraries, and who expect control over the distribution of inputs in Hypothesis, via e.g. a ``scale`` parameter for size or a ``frequency`` parameter for relative probabilities.
77

88
Hypothesis makes a distinction between the *domain* of a strategy, and the *distribution* of a strategy.
99

1010
The *domain* is the set of inputs that should be possible to generate. For instance, in ``lists(integers())``, the domain is lists of integers. For other strategies, particularly those that use |st.composite| or |assume| in their definition, the domain might be more complex.
1111

1212
The *distribution* is the probability with which different elements in the domain should be generated. For ``lists(integers())``, should Hypothesis generate many small lists? Large lists? More positive or more negative numbers? etc.
1313

14-
Hypothesis takes a philosophical stance that property-based testing libraries, not the user, should be responsible for selecting the distribution. As an intentional design choice, Hypothesis therefore lets you control the domain of inputs to your test, but not the distribution.
14+
Hypothesis takes a philosophical stance that while users may be responsible for selecting the domain, the property-based testing library—not the usershould be responsible for selecting the distribution. As an intentional design choice, Hypothesis therefore lets you control the domain of inputs to your test, but not the distribution.
1515

16-
There are a few reasons for this. One is that humans are pretty bad at choosing bug-finding distributions! Some bugs are "known unknowns": you had a good idea that some part of the code was buggy in a particular way. Others are "unknown unknowns": you had no idea that a certain kind of bug was even possible until you stumbled across it. Humans tend to overtune distributions for the former kind of bug, and not enough for the latter.
16+
Why not let users control the distribution?
17+
-------------------------------------------
1718

18-
To complicate things, the ideal distribution of a strategy depends not only on your project, but also on the property being tested. A strategy used in many places may be well-tuned by hand for one property, but badly tuned for another.
19+
There are a few reasons Hypothesis doesn't let users control the distribution.
1920

20-
Another reason is that the distribution of inputs is a deeply internal implementation detail. We frequently make changes to the distributions of strategies, either in an explicit change for that strategy, or as an implicit consequence from other work on the Hypothesis engine. Exposing control over the distribution would lock us into a public API that may make improvements to Hypothesis more difficult.
21+
* Humans are pretty bad at choosing bug-finding distributions! Some bugs are "known unknowns": you suspected that a part of the codebase was buggy in a particular way. Others are "unknown unknowns": you didn't know that a bug was possible until stumbling across it. Humans tend to overtune distributions for the former kind of bug, and not enough for the latter.
22+
* The ideal strategy distribution depends not only on the codebase, but also on the property being tested. A strategy used in many places may have a good distribution for one property, but not another.
23+
* The distribution of inputs is a deeply internal implementation detail. We sometimes change strategy distributions, either explicitly, or implicitly from other work on the Hypothesis engine. Exposing this would lock us into a public API that may make improvements to Hypothesis more difficult.
2124

22-
We're not saying that control over the distribution isn't useful! We occasionally receive requests to expose the distribution in Hypothesis (`e.g. <https://github.com/HypothesisWorks/hypothesis/issues/4205>`__), and users wouldn't be asking for it if it wasn't.
25+
Finally, we think distribution control is better handled with |alternative backends|. If existing backends like ``hypofuzz`` and ``crosshair`` don't suit your needs, you can also write your own. Backends can automatically generalize and adapt to the strategy and property being tested and avoid most of the problems above.
2326

24-
However, adding this would make it easy for users to unknowingly weaken their tests and would add maintenance overhead to Hypothesis, and so we haven't yet done so.
27+
We're not saying that control over the distribution isn't useful! We occasionally receive requests to expose the distribution in Hypothesis (`e.g. <https://github.com/HypothesisWorks/hypothesis/issues/4205>`__), and users wouldn't be asking for it if it wasn't. However, adding this to the public strategy API would make it easy for users to unknowingly weaken their tests, and would add maintenance overhead to Hypothesis, and so we haven't yet done so.

hypothesis-python/docs/explanation/example-count.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Examples which are too large
6666

6767
For performance reasons, Hypothesis places an internal limit on the size of a single example. If an example exceeds this size limit, we will retry generating it and will not count it towards the |max_examples| limit. (And if we see too many of these large examples, we will raise |HealthCheck.data_too_large|, unless suppressed with |settings.suppress_health_check|).
6868

69-
The specific value of the size limit is an undocumented implementation detail. The majority of Hypothesis tests do not come close to hitting it.
69+
The specific value of this size limit is an undocumented implementation detail. The majority of Hypothesis tests do not come close to hitting it.
7070

7171
Failing examples
7272
----------------

hypothesis-python/docs/extensions.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,19 @@ hypothesis-urandom
255255

256256
``/dev/urandom`` is not available on Windows, so we emit a warning and fall back to the
257257
hypothesis backend there.
258+
hypofuzz
259+
Generates inputs using coverage-guided fuzzing. See `HypoFuzz <https://hypofuzz.com/>`_ for details.
260+
261+
Requires ``pip install hypofuzz``.
258262
crosshair
259-
Generates examples using SMT solvers like z3, which is particularly effective at satisfying
263+
Generates inputs using SMT solvers like z3, which is particularly effective at satisfying
260264
difficult checks in your code, like ``if`` or ``==`` statements.
261265

262266
Requires ``pip install hypothesis[crosshair]``.
263267

264268
You can change the backend for a test with the |settings.backend| setting. For instance, after
265269
``pip install hypothesis[crosshair]``, you can use :pypi:`crosshair <crosshair-tool>` to
266-
generate examples with SMT via the :pypi:`hypothesis-crosshair` backend:
270+
generate inputs with SMT via the :pypi:`hypothesis-crosshair` backend:
267271

268272
.. code-block:: python
269273
@@ -275,4 +279,4 @@ generate examples with SMT via the :pypi:`hypothesis-crosshair` backend:
275279
assert x != 123456789
276280
277281
Failures found by alternative backends are saved to the database and shrink just like normally
278-
generated examples, and in general interact with every feature of Hypothesis as you would expect.
282+
generated inputs, and in general interact with every feature of Hypothesis as you would expect.

hypothesis-python/docs/how-to/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
How-to guides
22
=============
33

4-
Practical guides for applying Hypothesis in specific scenarios. Each guide addresses a particular question about using Hypothesis.
4+
These how-to pages are practical guides for applying Hypothesis in specific scenarios. Each page addresses a particular question about using Hypothesis.
55

66
.. toctree::
77
:maxdepth: 1

0 commit comments

Comments
 (0)