Skip to content

Commit 9a8422c

Browse files
committed
Observe backend in how_generated
1 parent 284c99b commit 9a8422c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
This patch includes the :obj:`~hypothesis.settings.backend` setting in the
4+
``how_generated`` field of our :doc:`observability output <observability>`.

hypothesis-python/src/hypothesis/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ def __init__(self, stuff, test, settings, random, wrapped_test):
786786
self.explain_traces = defaultdict(set)
787787
self._start_timestamp = time.time()
788788
self._string_repr = ""
789-
self._jsonable_arguments = {}
790789
self._timing_features = {}
791790

792791
@property
@@ -913,7 +912,7 @@ def run(data):
913912
),
914913
)
915914
self._string_repr = printer.getvalue()
916-
self._jsonable_arguments = {
915+
data._observability_arguments = {
917916
**dict(enumerate(map(to_jsonable, args))),
918917
**{k: to_jsonable(v) for k, v in kwargs.items()},
919918
}
@@ -1085,19 +1084,23 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
10851084
# Conditional here so we can save some time constructing the payload; in
10861085
# other cases (without coverage) it's cheap enough to do that regardless.
10871086
if TESTCASE_CALLBACKS:
1088-
if self.failed_normally or self.failed_due_to_deadline:
1089-
phase = "shrink"
1090-
elif runner := getattr(self, "_runner", None):
1087+
if runner := getattr(self, "_runner", None):
10911088
phase = runner._current_phase
1089+
elif self.failed_normally or self.failed_due_to_deadline:
1090+
phase = "shrink"
10921091
else: # pragma: no cover # in case of messing with internals
10931092
phase = "unknown"
1093+
backend_desc = f", using backend={self.settings.backend!r}" * (
1094+
self.settings.backend != "hypothesis"
1095+
and not getattr(runner, "_switch_to_hypothesis_provider", False)
1096+
)
10941097
tc = make_testcase(
10951098
start_timestamp=self._start_timestamp,
10961099
test_name_or_nodeid=self.test_identifier,
10971100
data=data,
1098-
how_generated=f"generated during {phase} phase",
1101+
how_generated=f"during {phase} phase{backend_desc}",
10991102
string_repr=self._string_repr,
1100-
arguments={**self._jsonable_arguments, **data._observability_args},
1103+
arguments=data._observability_args,
11011104
timing=self._timing_features,
11021105
coverage=tractable_coverage_report(trace) or None,
11031106
phase=phase,
@@ -1217,7 +1220,7 @@ def run_engine(self):
12171220
"status": "passed" if sys.exc_info()[0] else "failed",
12181221
"status_reason": str(origin or "unexpected/flaky pass"),
12191222
"representation": self._string_repr,
1220-
"arguments": self._jsonable_arguments,
1223+
"arguments": ran_example._observability_args,
12211224
"how_generated": "minimal failing example",
12221225
"features": {
12231226
**{

hypothesis-python/src/hypothesis/internal/observability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def make_testcase(
3636
start_timestamp: float,
3737
test_name_or_nodeid: str,
3838
data: ConjectureData,
39-
how_generated: str = "unknown",
39+
how_generated: str,
4040
string_repr: str = "<unknown>",
4141
arguments: Optional[dict] = None,
4242
timing: Dict[str, float],

0 commit comments

Comments
 (0)