Skip to content

Commit 81400a4

Browse files
committed
Observability from backends
1 parent d8d92a4 commit 81400a4

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RELEASE_TYPE: minor
2+
3+
:ref:`alternative-backends` can now implement a ``.get_observability_data()``
4+
method, providing the ``x['metadata']['backend']`` dictionary in our
5+
:doc:`observability output <observability>` (:issue:`3845` and `hypothesis-crosshair#22
6+
<https://github.com/pschanely/hypothesis-crosshair/issues/22>`__).

hypothesis-python/src/hypothesis/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
11221122
data._observability_args
11231123
)
11241124
self._string_repr = data.provider.realize(self._string_repr)
1125+
backend_metadata = data.provider.get_observability_data()
11251126
tc = make_testcase(
11261127
start_timestamp=self._start_timestamp,
11271128
test_name_or_nodeid=self.test_identifier,
@@ -1132,6 +1133,7 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
11321133
timing=self._timing_features,
11331134
coverage=tractable_coverage_report(trace) or None,
11341135
phase=phase,
1136+
backend_metadata=backend_metadata,
11351137
)
11361138
deliver_json_blob(tc)
11371139
self._timing_features = {}

hypothesis-python/src/hypothesis/internal/conjecture/data.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,16 @@ def realize(self, value: T) -> T:
12401240
12411241
The returned value should be non-symbolic.
12421242
"""
1243-
12441243
return value
12451244

1245+
def get_observability_data(self) -> Dict[str, Any]:
1246+
"""Called at the end of the test case when observability mode is active.
1247+
1248+
The return value should be a non-symbolic json-encodable dictionary,
1249+
and will be included as `observation["metadata"]["backend"]`.
1250+
"""
1251+
return {}
1252+
12461253
@abc.abstractmethod
12471254
def draw_boolean(
12481255
self,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import warnings
1818
from datetime import date, timedelta
1919
from functools import lru_cache
20-
from typing import Callable, Dict, List, Optional
20+
from typing import Any, Callable, Dict, List, Optional
2121

2222
from hypothesis.configuration import storage_directory
2323
from hypothesis.errors import HypothesisWarning
@@ -42,6 +42,7 @@ def make_testcase(
4242
timing: Dict[str, float],
4343
coverage: Optional[Dict[str, List[int]]] = None,
4444
phase: Optional[str] = None,
45+
backend_metadata: Optional[Dict[str, Any]] = None,
4546
) -> dict:
4647
if data.interesting_origin:
4748
status_reason = str(data.interesting_origin)
@@ -74,6 +75,7 @@ def make_testcase(
7475
"metadata": {
7576
"traceback": getattr(data.extra_information, "_expected_traceback", None),
7677
"predicates": data._observability_predicates,
78+
"backend": backend_metadata or {},
7779
**_system_metadata(),
7880
},
7981
"coverage": coverage,

0 commit comments

Comments
 (0)