summaryrefslogtreecommitdiffstats
path: root/contrib/python/hypothesis
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-12-20 12:11:43 +0300
committerrobot-piglet <[email protected]>2025-12-20 12:21:53 +0300
commit5d0f176bd168723921805abcfa7e21fc28bcbf77 (patch)
tree1c8b9498ff71feaffaeab8619ff933344275b079 /contrib/python/hypothesis
parente76fe1ca725964b10b1a512053505cd8fe3d44d0 (diff)
Intermediate changes
commit_hash:38959c894056348ff3a7dd592d6f7980b53684af
Diffstat (limited to 'contrib/python/hypothesis')
-rw-r--r--contrib/python/hypothesis/py3/.dist-info/METADATA2
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/_settings.py9
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/core.py71
-rw-r--r--contrib/python/hypothesis/py3/hypothesis/version.py2
-rw-r--r--contrib/python/hypothesis/py3/ya.make2
5 files changed, 68 insertions, 18 deletions
diff --git a/contrib/python/hypothesis/py3/.dist-info/METADATA b/contrib/python/hypothesis/py3/.dist-info/METADATA
index a93de1df8c0..7d3b5befe37 100644
--- a/contrib/python/hypothesis/py3/.dist-info/METADATA
+++ b/contrib/python/hypothesis/py3/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: hypothesis
-Version: 6.148.6
+Version: 6.148.7
Summary: The property-based testing library for Python
Author-email: "David R. MacIver and Zac Hatfield-Dodds" <[email protected]>
License-Expression: MPL-2.0
diff --git a/contrib/python/hypothesis/py3/hypothesis/_settings.py b/contrib/python/hypothesis/py3/hypothesis/_settings.py
index b34bff2a02f..13c90373ed0 100644
--- a/contrib/python/hypothesis/py3/hypothesis/_settings.py
+++ b/contrib/python/hypothesis/py3/hypothesis/_settings.py
@@ -80,8 +80,13 @@ class Verbosity(Enum):
verbose = "verbose"
"""
Increased verbosity. In addition to everything in |Verbosity.normal|, Hypothesis
- will print each example as it tries it, as well as any notes made with |note|
- for every example. Hypothesis will also print shrinking attempts.
+ will:
+
+ * Print each test case as it tries it
+ * Print any notes made with |note| for each test case
+ * Print each shrinking attempt
+ * Print all explicit failing examples when using |@example|, instead of only
+ the simplest one
"""
debug = "debug"
diff --git a/contrib/python/hypothesis/py3/hypothesis/core.py b/contrib/python/hypothesis/py3/hypothesis/core.py
index e0d02ab7701..66fb9fcba1d 100644
--- a/contrib/python/hypothesis/py3/hypothesis/core.py
+++ b/contrib/python/hypothesis/py3/hypothesis/core.py
@@ -9,6 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.
"""This module provides the core primitives of Hypothesis, such as given."""
+
import base64
import contextlib
import dataclasses
@@ -166,6 +167,12 @@ class Example:
reason: Any = field(default=None)
+@dataclass(slots=True, frozen=True)
+class ReportableError:
+ fragments: list[str]
+ exception: BaseException
+
+
# TODO_DOCS link to not-yet-existent patch-dumping docs
@@ -664,7 +671,7 @@ def execute_explicit_examples(state, wrapped_test, arguments, kwargs, original_s
with contextlib.suppress(StopTest):
empty_data.conclude_test(Status.INVALID)
- yield (fragments_reported, err)
+ yield ReportableError(fragments_reported, err)
if (
state.settings.report_multiple_bugs
and pytest_shows_exceptiongroups
@@ -1505,20 +1512,19 @@ class StateForActualGivenExecution:
# (note: e is a BaseException)
[falsifying_example.expected_exception or e],
)
- errors_to_report.append((fragments, err))
+ errors_to_report.append(ReportableError(fragments, err))
except UnsatisfiedAssumption as e: # pragma: no cover # ironically flaky
err = FlakyFailure(
"Unreliable assumption: An example which satisfied "
"assumptions on the first run now fails it.",
[e],
)
- errors_to_report.append((fragments, err))
+ errors_to_report.append(ReportableError(fragments, err))
except BaseException as e:
# If we have anything for explain-mode, this is the time to report.
fragments.extend(explanations[falsifying_example.interesting_origin])
- errors_to_report.append(
- (fragments, e.with_traceback(get_trimmed_traceback()))
- )
+ error_with_tb = e.with_traceback(get_trimmed_traceback())
+ errors_to_report.append(ReportableError(fragments, error_with_tb))
tb = format_exception(e, get_trimmed_traceback(e))
origin = InterestingOrigin.from_exception(e)
else:
@@ -1567,27 +1573,61 @@ class StateForActualGivenExecution:
)
+def _simplify_explicit_errors(errors: list[ReportableError]) -> list[ReportableError]:
+ """
+ Group explicit example errors by their InterestingOrigin, keeping only the
+ simplest one, and adding a note of how many other examples failed with the same
+ error.
+ """
+ by_origin: dict[InterestingOrigin, list[ReportableError]] = defaultdict(list)
+ for error in errors:
+ origin = InterestingOrigin.from_exception(error.exception)
+ by_origin[origin].append(error)
+
+ result = []
+ for group in by_origin.values():
+ if len(group) == 1:
+ result.append(group[0])
+ else:
+ # Sort by shortlex of representation (first fragment)
+ def shortlex_key(error):
+ repr_str = error.fragments[0] if error.fragments else ""
+ return (len(repr_str), repr_str)
+
+ sorted_group = sorted(group, key=shortlex_key)
+ simplest = sorted_group[0]
+ other_count = len(group) - 1
+ add_note(
+ simplest.exception,
+ f"(note: {other_count} other explicit example{'s' * (other_count > 1)} "
+ "also failed with this error; use Verbosity.verbose to view)",
+ )
+ result.append(simplest)
+
+ return result
+
+
def _raise_to_user(
errors_to_report, settings, target_lines, trailer="", *, unsound_backend=None
):
"""Helper function for attaching notes and grouping multiple errors."""
failing_prefix = "Falsifying example: "
ls = []
- for fragments, err in errors_to_report:
- for note in fragments:
- add_note(err, note)
+ for error in errors_to_report:
+ for note in error.fragments:
+ add_note(error.exception, note)
if note.startswith(failing_prefix):
ls.append(note.removeprefix(failing_prefix))
if current_pytest_item.value:
current_pytest_item.value._hypothesis_failing_examples = ls
if len(errors_to_report) == 1:
- _, the_error_hypothesis_found = errors_to_report[0]
+ the_error_hypothesis_found = errors_to_report[0].exception
else:
assert errors_to_report
the_error_hypothesis_found = BaseExceptionGroup(
f"Hypothesis found {len(errors_to_report)} distinct failures{trailer}.",
- [e for _, e in errors_to_report],
+ [error.exception for error in errors_to_report],
)
if settings.verbosity >= Verbosity.normal:
@@ -1596,7 +1636,7 @@ def _raise_to_user(
if unsound_backend:
add_note(
- err,
+ the_error_hypothesis_found,
f"backend={unsound_backend!r} claimed to verify this test passes - "
"please send them a bug report!",
)
@@ -2120,10 +2160,15 @@ def given(
# If an explicit example raised a 'skip' exception, ensure it's never
# wrapped up in an exception group. Because we break out of the loop
# immediately on finding a skip, if present it's always the last error.
- if isinstance(errors[-1][1], skip_exceptions_to_reraise()):
+ if isinstance(errors[-1].exception, skip_exceptions_to_reraise()):
# Covered by `test_issue_3453_regression`, just in a subprocess.
del errors[:-1] # pragma: no cover
+ if state.settings.verbosity < Verbosity.verbose:
+ # keep only one error per interesting origin, unless
+ # verbosity is high
+ errors = _simplify_explicit_errors(errors)
+
_raise_to_user(errors, state.settings, [], " in explicit examples")
# If there were any explicit examples, they all ran successfully.
diff --git a/contrib/python/hypothesis/py3/hypothesis/version.py b/contrib/python/hypothesis/py3/hypothesis/version.py
index 477c8a8b51a..742d0039769 100644
--- a/contrib/python/hypothesis/py3/hypothesis/version.py
+++ b/contrib/python/hypothesis/py3/hypothesis/version.py
@@ -8,5 +8,5 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
-__version_info__ = (6, 148, 6)
+__version_info__ = (6, 148, 7)
__version__ = ".".join(map(str, __version_info__))
diff --git a/contrib/python/hypothesis/py3/ya.make b/contrib/python/hypothesis/py3/ya.make
index 700515dc59a..b11caef1717 100644
--- a/contrib/python/hypothesis/py3/ya.make
+++ b/contrib/python/hypothesis/py3/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(6.148.6)
+VERSION(6.148.7)
LICENSE(MPL-2.0)