Skip to content

Commit ae171e0

Browse files
authored
Merge pull request #3432 from Zac-HD/fix-exceptiongroup-display-workaround
Fix pytest workaround for `ExceptionGroup` display
2 parents 81fb173 + df1896e commit ae171e0

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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+
This patch fixes our workaround for `a pytest bug where the inner exceptions in
4+
an ExceptionGroup are not displayed <https://github.com/pytest-dev/pytest/issues/9159>`__
5+
(:issue:`3430`).

hypothesis-python/src/_hypothesis_pytestplugin.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,6 @@ def pytest_configure(config):
178178
pass
179179
core.global_force_seed = seed
180180

181-
core.pytest_shows_exceptiongroups = (
182-
sys.version_info[:2] >= (3, 11)
183-
## See https://github.com/pytest-dev/pytest/issues/9159
184-
# or pytest_version >= (7, 2) # TODO: fill in correct version here
185-
or config.getoption("tbstyle", "auto") == "native"
186-
)
187-
188181
@pytest.hookimpl(hookwrapper=True)
189182
def pytest_runtest_call(item):
190183
__tracebackhide__ = True
@@ -195,6 +188,11 @@ def pytest_runtest_call(item):
195188
from hypothesis import core
196189
from hypothesis.internal.detection import is_hypothesis_test
197190

191+
## See https://github.com/pytest-dev/pytest/issues/9159
192+
# TODO: add `pytest_version >= (7, 2) or` once the issue above is fixed.
193+
core.pytest_shows_exceptiongroups = (
194+
item.config.getoption("tbstyle", "auto") == "native"
195+
)
198196
core.running_under_pytest = True
199197

200198
if not is_hypothesis_test(item.obj):

hypothesis-python/tests/pytest/test_reporting.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

11+
import pytest
12+
1113
pytest_plugins = "pytester"
1214

1315

@@ -33,3 +35,24 @@ def test_runs_reporting_hook(testdir):
3335
assert "Captured stdout call" not in out
3436
assert "Falsifying example" in out
3537
assert result.ret != 0
38+
39+
40+
TEST_EXCEPTIONGROUP = """
41+
from hypothesis import given, strategies as st
42+
43+
@given(x=st.booleans())
44+
def test_fuzz_sorted(x):
45+
raise ValueError if x else TypeError
46+
"""
47+
48+
49+
@pytest.mark.parametrize("tb", ["auto", "long", "short", "native"])
50+
def test_no_missing_reports(testdir, tb):
51+
script = testdir.makepyfile(TEST_EXCEPTIONGROUP)
52+
result = testdir.runpytest(script, f"--tb={tb}")
53+
out = "\n".join(result.stdout.lines)
54+
# If the False case is missing, that means we're not printing exception info.
55+
# See https://github.com/HypothesisWorks/hypothesis/issues/3430 With --tb=native,
56+
# we should show the full ExceptionGroup with *both* errors.
57+
assert "x=False" in out
58+
assert "x=True" in out or tb != "native"

0 commit comments

Comments
 (0)