Skip to content

Commit db39f73

Browse files
authored
Merge pull request #3455 from Zac-HD/example-consistency
Consistent skipping from explicit examples
2 parents 19cfbde + 9cbc00f commit db39f73

File tree

8 files changed

+59
-16
lines changed

8 files changed

+59
-16
lines changed

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ if [ -n "${GITHUB_ACTIONS-}" ] || [ -n "${CODESPACES-}" ] ; then
2323
else
2424
# Otherwise, we install it from scratch
2525
# NOTE: tooling keeps this version in sync with ci_version in tooling
26-
"$SCRIPTS/ensure-python.sh" 3.8.13
27-
PYTHON=$(pythonloc 3.8.13)/bin/python
26+
"$SCRIPTS/ensure-python.sh" 3.8.14
27+
PYTHON=$(pythonloc 3.8.14)/bin/python
2828
fi
2929

3030
TOOL_REQUIREMENTS="$ROOT/requirements/tools.txt"

hypothesis-python/.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exclude_lines =
1919
def __copy__
2020
def __deepcopy__
2121
except ImportError:
22+
except ModuleNotFoundError:
2223
if PYPY:
2324
if TYPE_CHECKING:
2425
if "\w+" in sys\.modules:

hypothesis-python/RELEASE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RELEASE_TYPE: patch
2+
3+
If multiple explicit examples (from :func:`@example() <hypothesis.example>`)
4+
raise a Skip exception, for consistency with generated examples we now re-raise
5+
the first instead of collecting them into an ExceptionGroup (:issue:`3453`).

hypothesis-python/src/hypothesis/core.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,11 @@ def execute_explicit_examples(state, wrapped_test, arguments, kwargs, original_s
437437
err = new
438438

439439
yield (fragments_reported, err)
440-
if state.settings.report_multiple_bugs and pytest_shows_exceptiongroups:
440+
if (
441+
state.settings.report_multiple_bugs
442+
and pytest_shows_exceptiongroups
443+
and not isinstance(err, skip_exceptions_to_reraise())
444+
):
441445
continue
442446
break
443447
finally:
@@ -1192,6 +1196,14 @@ def wrapped_test(*arguments, **kwargs):
11921196
# If we're not going to report multiple bugs, we would have
11931197
# stopped running explicit examples at the first failure.
11941198
assert len(errors) == 1 or state.settings.report_multiple_bugs
1199+
1200+
# If an explicit example raised a 'skip' exception, ensure it's never
1201+
# wrapped up in an exception group. Because we break out of the loop
1202+
# immediately on finding a skip, if present it's always the last error.
1203+
if isinstance(errors[-1][1], skip_exceptions_to_reraise()):
1204+
# Covered by `test_issue_3453_regression`, just in a subprocess.
1205+
del errors[:-1] # pragma: no cover
1206+
11951207
_raise_to_user(errors, state.settings, [], " in explicit examples")
11961208

11971209
# If there were any explicit examples, they all ran successfully.

hypothesis-python/src/hypothesis/extra/codemods.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ def leave_Call(self, original_node, updated_node):
197197
# Get the actual function object so that we can inspect the signature.
198198
# This does e.g. incur a dependency on Numpy to fix Numpy-dependent code,
199199
# but having a single source of truth about the signatures is worth it.
200-
params = signature(get_fn(*qualnames)).parameters.values()
200+
try:
201+
params = signature(get_fn(*qualnames)).parameters.values()
202+
except ModuleNotFoundError:
203+
return updated_node
201204

202205
# st.floats() has a new allow_subnormal kwonly argument not at the end,
203206
# so we do a bit more of a dance here.

hypothesis-python/tests/pytest/test_skipping.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,25 @@ def test_no_falsifying_example_if_pytest_skip(testdir):
3939
)
4040
out = "\n".join(result.stdout.lines)
4141
assert "Falsifying example" not in out
42+
43+
44+
def test_issue_3453_regression(testdir):
45+
"""If ``pytest.skip() is called during a test, Hypothesis should not
46+
continue running the test and shrink process, nor should it print anything
47+
about falsifying examples."""
48+
script = testdir.makepyfile(
49+
"""
50+
from hypothesis import example, given, strategies as st
51+
import pytest
52+
53+
@given(value=st.none())
54+
@example("hello")
55+
@example("goodbye")
56+
def test_skip_on_first_skipping_example(value):
57+
assert value is not None
58+
assert value != "hello" # queue up a non-skip error which must be discarded
59+
pytest.skip()
60+
"""
61+
)
62+
result = testdir.runpytest(script, "--tb=native")
63+
result.assert_outcomes(skipped=1)

requirements/tools.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bleach==5.0.1
3535
# via readme-renderer
3636
build==0.8.0
3737
# via pip-tools
38-
certifi==2022.6.15.1
38+
certifi==2022.9.14
3939
# via requests
4040
cffi==1.15.1
4141
# via cryptography
@@ -94,7 +94,7 @@ flake8-2020==1.7.0
9494
# via -r requirements/tools.in
9595
flake8-bandit==4.1.1
9696
# via -r requirements/tools.in
97-
flake8-bugbear==22.8.23
97+
flake8-bugbear==22.9.11
9898
# via -r requirements/tools.in
9999
flake8-builtins==1.5.3
100100
# via -r requirements/tools.in
@@ -124,7 +124,7 @@ gitdb==4.0.9
124124
# via gitpython
125125
gitpython==3.1.27
126126
# via bandit
127-
idna==3.3
127+
idna==3.4
128128
# via requests
129129
imagesize==1.4.1
130130
# via sphinx
@@ -149,7 +149,7 @@ jeepney==0.8.0
149149
# secretstorage
150150
jinja2==3.1.2
151151
# via sphinx
152-
keyring==23.9.1
152+
keyring==23.9.3
153153
# via twine
154154
lark-parser==0.12.0
155155
# via -r requirements/tools.in
@@ -232,15 +232,15 @@ pygments==2.13.0
232232
# sphinx
233233
pyparsing==3.0.9
234234
# via packaging
235-
pyright==1.1.270
235+
pyright==1.1.271
236236
# via -r requirements/tools.in
237237
pytest==7.1.3
238238
# via -r requirements/tools.in
239239
python-dateutil==2.8.2
240240
# via -r requirements/tools.in
241241
pytz==2022.2.1
242242
# via babel
243-
pyupgrade==2.37.3
243+
pyupgrade==2.38.0
244244
# via shed
245245
pyyaml==6.0
246246
# via
@@ -264,7 +264,7 @@ rich==12.5.1
264264
# via twine
265265
secretstorage==3.3.3
266266
# via keyring
267-
shed==0.10.2
267+
shed==0.10.3
268268
# via -r requirements/tools.in
269269
six==1.16.0
270270
# via
@@ -288,7 +288,7 @@ sphinx==5.1.1
288288
# sphinx-codeautolink
289289
# sphinx-hoverxref
290290
# sphinx-rtd-theme
291-
sphinx-codeautolink==0.11.0
291+
sphinx-codeautolink==0.12.0
292292
# via -r requirements/tools.in
293293
sphinx-hoverxref==1.1.3
294294
# via -r requirements/tools.in
@@ -330,7 +330,7 @@ tomli==2.0.1
330330
# tox
331331
tox==3.26.0
332332
# via -r requirements/tools.in
333-
traitlets==5.3.0
333+
traitlets==5.4.0
334334
# via
335335
# ipython
336336
# matplotlib-inline

tooling/src/hypothesistooling/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ def run_tox(task, version, *args):
380380
# When a version is added or removed, manually update the env lists in tox.ini and
381381
# workflows/main.yml, and the `Programming Language ::` specifiers in setup.py
382382
PYTHONS = {
383-
"3.7": "3.7.13",
384-
"3.8": "3.8.13",
385-
"3.9": "3.9.13",
383+
"3.7": "3.7.14",
384+
"3.8": "3.8.14",
385+
"3.9": "3.9.14",
386386
"3.10": "3.10.7",
387387
"3.11": "3.11-dev",
388388
"3.12": "3.12-dev",

0 commit comments

Comments
 (0)