Skip to content

Commit

Permalink
Observe backend in how_generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Mar 24, 2024
1 parent 284c99b commit 9a8422c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RELEASE_TYPE: patch

This patch includes the :obj:`~hypothesis.settings.backend` setting in the
``how_generated`` field of our :doc:`observability output <observability>`.
19 changes: 11 additions & 8 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ def __init__(self, stuff, test, settings, random, wrapped_test):
self.explain_traces = defaultdict(set)
self._start_timestamp = time.time()
self._string_repr = ""
self._jsonable_arguments = {}
self._timing_features = {}

@property
Expand Down Expand Up @@ -913,7 +912,7 @@ def run(data):
),
)
self._string_repr = printer.getvalue()
self._jsonable_arguments = {
data._observability_arguments = {
**dict(enumerate(map(to_jsonable, args))),
**{k: to_jsonable(v) for k, v in kwargs.items()},
}
Expand Down Expand Up @@ -1085,19 +1084,23 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
# Conditional here so we can save some time constructing the payload; in
# other cases (without coverage) it's cheap enough to do that regardless.
if TESTCASE_CALLBACKS:
if self.failed_normally or self.failed_due_to_deadline:
phase = "shrink"
elif runner := getattr(self, "_runner", None):
if runner := getattr(self, "_runner", None):
phase = runner._current_phase
elif self.failed_normally or self.failed_due_to_deadline:
phase = "shrink"
else: # pragma: no cover # in case of messing with internals
phase = "unknown"
backend_desc = f", using backend={self.settings.backend!r}" * (
self.settings.backend != "hypothesis"
and not getattr(runner, "_switch_to_hypothesis_provider", False)
)
tc = make_testcase(
start_timestamp=self._start_timestamp,
test_name_or_nodeid=self.test_identifier,
data=data,
how_generated=f"generated during {phase} phase",
how_generated=f"during {phase} phase{backend_desc}",
string_repr=self._string_repr,
arguments={**self._jsonable_arguments, **data._observability_args},
arguments=data._observability_args,
timing=self._timing_features,
coverage=tractable_coverage_report(trace) or None,
phase=phase,
Expand Down Expand Up @@ -1217,7 +1220,7 @@ def run_engine(self):
"status": "passed" if sys.exc_info()[0] else "failed",
"status_reason": str(origin or "unexpected/flaky pass"),
"representation": self._string_repr,
"arguments": self._jsonable_arguments,
"arguments": ran_example._observability_args,
"how_generated": "minimal failing example",
"features": {
**{
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/internal/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def make_testcase(
start_timestamp: float,
test_name_or_nodeid: str,
data: ConjectureData,
how_generated: str = "unknown",
how_generated: str,
string_repr: str = "<unknown>",
arguments: Optional[dict] = None,
timing: Dict[str, float],
Expand Down

0 comments on commit 9a8422c

Please sign in to comment.