Skip to content

Commit 18c2a59

Browse files
committed
test: conditional use of Hypothesis
In 6.156.0, Hypothesis stopped providing PyPy 3.10 wheels. This conditionalizes our use so we can completely avoid it when needed. It seems like Hypothesis might be on the bleeding edge of build tools etc, so we may need this in the future for other trailing edge environments.
1 parent b77cd71 commit 18c2a59

13 files changed

Lines changed: 118 additions & 53 deletions

File tree

‎requirements/dev.pip‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ execnet==2.1.2 \
323323
--hash=sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd \
324324
--hash=sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec
325325
# via pytest-xdist
326-
filelock==3.30.1 \
327-
--hash=sha256:69b98bab51bed4c86b141ef338f85ca07937573e8a7798f7fe6a31ccd94b9338 \
328-
--hash=sha256:6ad1b1ec6a5e2c91e02979b7d1096e5e964d83ad8a55679bacd1d96f917fda6e
326+
filelock==3.30.2 \
327+
--hash=sha256:1ea7c857465c897a4a6e64c1aace28ff6b83f5bc66c1c06ea148efa65bc2ec5d \
328+
--hash=sha256:a64b58f75048ec39589983e97f5117163f822261dcb6ba843e098f05aac9663f
329329
# via
330330
# python-discovery
331331
# tox
@@ -415,7 +415,7 @@ greenlet==3.5.3 \
415415
--hash=sha256:fad5aec764399f1b5cc347ad250a59660f20c8f8888ea6bae1f93b769cce1154 \
416416
--hash=sha256:fd2e02fa07485778536a036222d616ab957b1d533f36b3ed98ce725d9c9d3117
417417
# via -r requirements/dev.in
418-
hypothesis==6.156.6 \
418+
hypothesis==6.156.6 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
419419
--hash=sha256:01bb8270c46b3ef53b0c2d23ff613ea506d609d06f936d823ea57c58b66b05f7 \
420420
--hash=sha256:02accb187617ebaebb120da931f799a3cb0df7c38706f97f9d022441d4faf533 \
421421
--hash=sha256:050c8c0815f88d47dd0875a92698d20d61639b7b721ee043a6d687c7f14ff7d8 \
@@ -802,7 +802,7 @@ setuptools==83.0.0 \
802802
# via
803803
# -r requirements/pip.in
804804
# check-manifest
805-
sortedcontainers==2.4.0 \
805+
sortedcontainers==2.4.0 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
806806
--hash=sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88 \
807807
--hash=sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0
808808
# via hypothesis
@@ -865,9 +865,9 @@ tomli-w==1.2.0 \
865865
--hash=sha256:188306098d013b691fcadc011abd66727d3c414c571bb01b1a174ba8c983cf90 \
866866
--hash=sha256:2dd14fac5a47c27be9cd4c976af5a12d87fb1f0b4512f81d69cce3b35ae25021
867867
# via tox
868-
tomlkit==0.15.0 \
869-
--hash=sha256:4dbc8f0fc024412b57ced8757ac7461305126a648ff8c2c807fcb8e133a78738 \
870-
--hash=sha256:7d1a9ecba3086638211b13814ea79c90dd54dd11993564376f3aa92271f5c7a3
868+
tomlkit==0.15.1 \
869+
--hash=sha256:177a05aece5a8ca5266fd3c448abb47b8d352f09d477d3ca8332db4d89b24304 \
870+
--hash=sha256:e25bbf38843005246210a12982776f27f99cb9be67160e14434d0c0d21ee1e97
871871
# via pylint
872872
tox==4.56.4 \
873873
--hash=sha256:53bac88382b9638a5ce40fbaddd6076e1c8f638751af7bf8e759392c953df2f0 \

‎requirements/kit.pip‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ docutils==0.23 \
291291
--hash=sha256:25d013af9bf23bc1c7b2b093dff4208166c53a94786c9e447808335ef1185fea \
292292
--hash=sha256:746f5060322511280a1e50eb76846ed6bf2342984b2ac04dc42caa1a8d78799e
293293
# via readme-renderer
294-
filelock==3.30.1 \
295-
--hash=sha256:69b98bab51bed4c86b141ef338f85ca07937573e8a7798f7fe6a31ccd94b9338 \
296-
--hash=sha256:6ad1b1ec6a5e2c91e02979b7d1096e5e964d83ad8a55679bacd1d96f917fda6e
294+
filelock==3.30.2 \
295+
--hash=sha256:1ea7c857465c897a4a6e64c1aace28ff6b83f5bc66c1c06ea148efa65bc2ec5d \
296+
--hash=sha256:a64b58f75048ec39589983e97f5117163f822261dcb6ba843e098f05aac9663f
297297
# via cibuildwheel
298298
humanize==4.16.0 \
299299
--hash=sha256:353eb2f34c09d098b2880eee8bef21832eae6d174f48c5762fff7e5fcb74d01d \

‎requirements/mypy.pip‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ flaky==3.8.1 \
5656
--hash=sha256:194ccf4f0d3a22b2de7130f4b62e45e977ac1b5ccad74d4d48f3005dcc38815e \
5757
--hash=sha256:47204a81ec905f3d5acfbd61daeabcada8f9d4031616d9bcb0618461729699f5
5858
# via -r requirements/pytest.in
59-
hypothesis==6.156.6 \
59+
hypothesis==6.156.6 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
6060
--hash=sha256:01bb8270c46b3ef53b0c2d23ff613ea506d609d06f936d823ea57c58b66b05f7 \
6161
--hash=sha256:02accb187617ebaebb120da931f799a3cb0df7c38706f97f9d022441d4faf533 \
6262
--hash=sha256:050c8c0815f88d47dd0875a92698d20d61639b7b721ee043a6d687c7f14ff7d8 \
@@ -293,7 +293,7 @@ pytest-xdist==3.8.0 \
293293
--hash=sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88 \
294294
--hash=sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1
295295
# via -r requirements/pytest.in
296-
sortedcontainers==2.4.0 \
296+
sortedcontainers==2.4.0 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
297297
--hash=sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88 \
298298
--hash=sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0
299299
# via hypothesis

‎requirements/pip.pip‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ distlib==0.4.3 \
44
--hash=sha256:4b0ce306c966eb73bc3a7b6abad017c556dadd92c44701562cd528ac7fde4d5b \
55
--hash=sha256:f152097224a0ae24be5a0f6bae1b9359af82133bce63f98a95f86cae1aede9ed
66
# via virtualenv
7-
filelock==3.30.1 \
8-
--hash=sha256:69b98bab51bed4c86b141ef338f85ca07937573e8a7798f7fe6a31ccd94b9338 \
9-
--hash=sha256:6ad1b1ec6a5e2c91e02979b7d1096e5e964d83ad8a55679bacd1d96f917fda6e
7+
filelock==3.30.2 \
8+
--hash=sha256:1ea7c857465c897a4a6e64c1aace28ff6b83f5bc66c1c06ea148efa65bc2ec5d \
9+
--hash=sha256:a64b58f75048ec39589983e97f5117163f822261dcb6ba843e098f05aac9663f
1010
# via
1111
# python-discovery
1212
# virtualenv

‎requirements/pytest.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# "make upgrade" turns this into requirements/pytest.pip.
88

99
flaky
10-
hypothesis
10+
hypothesis; platform_python_implementation != "PyPy" or python_version != "3.10"
1111
pygments # so that pytest will syntax-color.
1212
pytest
1313
pytest-xdist

‎requirements/pytest.pip‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ flaky==3.8.1 \
2020
--hash=sha256:194ccf4f0d3a22b2de7130f4b62e45e977ac1b5ccad74d4d48f3005dcc38815e \
2121
--hash=sha256:47204a81ec905f3d5acfbd61daeabcada8f9d4031616d9bcb0618461729699f5
2222
# via -r requirements/pytest.in
23-
hypothesis==6.156.6 \
23+
hypothesis==6.156.6 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
2424
--hash=sha256:01bb8270c46b3ef53b0c2d23ff613ea506d609d06f936d823ea57c58b66b05f7 \
2525
--hash=sha256:02accb187617ebaebb120da931f799a3cb0df7c38706f97f9d022441d4faf533 \
2626
--hash=sha256:050c8c0815f88d47dd0875a92698d20d61639b7b721ee043a6d687c7f14ff7d8 \
@@ -108,7 +108,7 @@ pytest-xdist==3.8.0 \
108108
--hash=sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88 \
109109
--hash=sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1
110110
# via -r requirements/pytest.in
111-
sortedcontainers==2.4.0 \
111+
sortedcontainers==2.4.0 ; python_full_version >= '3.11' or platform_python_implementation != 'PyPy' \
112112
--hash=sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88 \
113113
--hash=sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0
114114
# via hypothesis

‎requirements/tox.pip‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ distlib==0.4.3 \
1414
--hash=sha256:4b0ce306c966eb73bc3a7b6abad017c556dadd92c44701562cd528ac7fde4d5b \
1515
--hash=sha256:f152097224a0ae24be5a0f6bae1b9359af82133bce63f98a95f86cae1aede9ed
1616
# via virtualenv
17-
filelock==3.30.1 \
18-
--hash=sha256:69b98bab51bed4c86b141ef338f85ca07937573e8a7798f7fe6a31ccd94b9338 \
19-
--hash=sha256:6ad1b1ec6a5e2c91e02979b7d1096e5e964d83ad8a55679bacd1d96f917fda6e
17+
filelock==3.30.2 \
18+
--hash=sha256:1ea7c857465c897a4a6e64c1aace28ff6b83f5bc66c1c06ea148efa65bc2ec5d \
19+
--hash=sha256:a64b58f75048ec39589983e97f5117163f822261dcb6ba843e098f05aac9663f
2020
# via
2121
# python-discovery
2222
# tox

‎tests/conftest.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from collections.abc import Iterable
1717

18-
import hypothesis
1918
import pytest
2019

2120
from coverage.files import set_relative_directory
@@ -35,13 +34,16 @@
3534
"tests.select_plugin",
3635
]
3736

38-
# Control the Hypothesis settings.
39-
# $set_env.py: HYPOTHESIS_PROFILE - "slow": 25k examples; "250k"
40-
hypothesis.settings.register_profile("slow", max_examples=25_000)
41-
hypothesis.settings.register_profile("250k", max_examples=250_000)
42-
# In CI, using the database makes the first draw take more than a second.
43-
hypothesis.settings.register_profile("ci", database=None, max_examples=1000)
44-
hypothesis.settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
37+
if testenv.USE_HYPOTHESIS:
38+
import hypothesis
39+
40+
# Control the Hypothesis settings.
41+
# $set_env.py: HYPOTHESIS_PROFILE - "slow": 25k examples; "250k"
42+
hypothesis.settings.register_profile("slow", max_examples=25_000)
43+
hypothesis.settings.register_profile("250k", max_examples=250_000)
44+
# In CI, using the database makes the first draw take more than a second.
45+
hypothesis.settings.register_profile("ci", database=None, max_examples=1000)
46+
hypothesis.settings.load_profile(os.getenv("HYPOTHESIS_PROFILE", "default"))
4547

4648

4749
@pytest.fixture(autouse=True)

‎tests/hypo.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2+
# For details: https://github.com/coveragepy/coveragepy/blob/main/NOTICE.txt
3+
4+
"""A Hypothesis wrapper so we can turn it off completely in environments it doesn't support."""
5+
6+
from __future__ import annotations
7+
8+
from typing import Any
9+
10+
import pytest
11+
12+
from tests import testenv
13+
14+
# pylint: disable=useless-import-alias
15+
# pylint: disable=unused-import
16+
17+
if testenv.USE_HYPOTHESIS:
18+
from hypothesis import (
19+
example as example,
20+
given as given,
21+
settings as settings,
22+
)
23+
from hypothesis.strategies import (
24+
integers as integers,
25+
sets as sets,
26+
)
27+
else:
28+
29+
def _skip(*_args: Any, **_kwargs: Any) -> Any:
30+
"""A dummy decorator to skip hypothesis tests."""
31+
return pytest.mark.skip("Hypothesis isn't supported in this environment")
32+
33+
example = given = settings = _skip # type: ignore[misc,assignment]
34+
35+
def _dummy(*_args: Any, **_kwargs: Any) -> None:
36+
"""Replace Hypothesis tools with nothing."""
37+
return None
38+
39+
integers = sets = _dummy # type: ignore[assignment]

‎tests/strategies.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def nested_dicts_of(leaves: S[D]) -> S[dict[str, D]]:
8585
max_leaves=3,
8686
)
8787

88+
89+
# Use nested_data_strategies to generate data schemas, then use it twice in
90+
# the test to get two chunks of data with the "same shape" but different
91+
# data.
92+
nested_data_pairs = nested_data_strategies.flatmap(lambda s: st.tuples(s, s))
93+
94+
8895
if __name__ == "__main__":
8996
for _ in range(100):
9097
print(repr(nested_data_strategies.example().example()))

0 commit comments

Comments
 (0)