You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This release stabilizes our :ref:`observability interface <observability>`, which was previously marked as experimental. When observability is enabled, Hypothesis writes data about each test case to ``.hypothesis/observed`` in an analysis-ready `jsonlines <https://jsonlines.org/>`_ format, intended to help you understand the performance of your Hypothesis tests.
4
+
5
+
Observability can be controlled in two ways:
6
+
7
+
* via the new |settings.observability| argument,
8
+
* or via the ``HYPOTHESIS_OBSERVABILITY`` environment variable.
9
+
10
+
See :ref:`Configuring observability <observability-configuration>` for details.
11
+
12
+
If you use VSCode, we recommend the `Tyche <https://github.com/tyche-pbt/tyche-extension>`__ extension, a PBT-specific visualization tool designed for Hypothesis's observability interface.
Copy file name to clipboardExpand all lines: hypothesis-python/docs/changelog.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -668,11 +668,11 @@ Further improve the performance of the constants-collection feature introduced i
668
668
6.135.3 - 2025-06-08
669
669
--------------------
670
670
671
-
This release adds the experimental and unstable |OBSERVABILITY_CHOICES| option for :ref:`observability <observability>`. If set, the choice sequence is included in ``metadata.choice_nodes``, and choice sequence spans are included in ``metadata.choice_spans``.
671
+
This release adds the experimental and unstable ``OBSERVABILITY_CHOICES`` option for :ref:`observability <observability>`. If set, the choice sequence is included in ``metadata.choice_nodes``, and choice sequence spans are included in ``metadata.choice_spans``.
672
672
673
673
These are relatively low-level implementation detail of Hypothesis, and are exposed in observability for users building tools or research on top of Hypothesis. See |PrimitiveProvider| for more details about the choice sequence and choice spans.
674
674
675
-
We are actively working towards a better interface for this. Feel free to use |OBSERVABILITY_CHOICES| to experiment, but don't rely on it yet!
675
+
We are actively working towards a better interface for this. Feel free to use ``OBSERVABILITY_CHOICES`` to experiment, but don't rely on it yet!
Copy file name to clipboardExpand all lines: hypothesis-python/docs/reference/integrations.rst
+23-18Lines changed: 23 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,17 +75,10 @@ If you're interested in similar questions, `drop me an email`_!
75
75
Observability
76
76
-------------
77
77
78
-
.. note::
78
+
.. tip::
79
79
80
80
The `Tyche <https://github.com/tyche-pbt/tyche-extension>`__ VSCode extension provides an in-editor UI for observability results generated by Hypothesis. If you want to *view* observability results, rather than programmatically consume or display them, we recommend using Tyche.
81
81
82
-
.. warning::
83
-
84
-
This feature is experimental, and could have breaking changes or even be removed
85
-
without notice. Try it out, let us know what you think, but don't rely on it
86
-
just yet!
87
-
88
-
89
82
Motivation
90
83
~~~~~~~~~~
91
84
@@ -108,24 +101,36 @@ debuggers such as `rr <https://rr-project.org/>`__ or `pytrace <https://pytrace.
108
101
because there's no good way to compare multiple traces from these tools and their
109
102
Python support is relatively immature.
110
103
104
+
.. _observability-configuration:
105
+
106
+
Configuring observability
107
+
~~~~~~~~~~~~~~~~~~~~~~~~~
108
+
109
+
There are two ways to configure observability:
111
110
112
-
Configuration
113
-
~~~~~~~~~~~~~
111
+
* Setting the ``HYPOTHESIS_OBSERVABILITY`` environment variable. ``HYPOTHESIS_OBSERVABILITY`` may take one of the following values:
114
112
115
-
If you set the ``HYPOTHESIS_EXPERIMENTAL_OBSERVABILITY`` environment variable,
116
-
Hypothesis will log various observations to jsonlines files in the
113
+
* ``True``, ``true``, or ``1`` enables observability.
114
+
* ``False``, ``false``, or ``0`` disables observability (the default).
115
+
* ``HYPOTHESIS_OBSERVABILITY`` can be further customized with specific string values.
116
+
117
+
* ``HYPOTHESIS_OBSERVABILITY=coverage`` is equivalent to :obj:`settings(observability=["coverage"]) <hypothesis.settings.observability>`.
118
+
* ``HYPOTHESIS_OBSERVABILITY=choices`` is equivalent to :obj:`settings(observability=["choices"]) <hypothesis.settings.observability>`.
119
+
* ``HYPOTHESIS_OBSERVABILITY=choices,coverage`` is equivalent to :obj:`settings(observability=["choices", "coverage"]) <hypothesis.settings.observability>`.
120
+
* and so on.
121
+
122
+
* Setting |settings.observability| on a specific test. See the docs there for details. |settings.observability| can be configured in the same way as ``HYPOTHESIS_OBSERVABILITY``.
123
+
124
+
If neither ``HYPOTHESIS_OBSERVABILITY`` or |settings.observability| are set, observability is disabled.
125
+
126
+
When observability is configured, Hypothesis will log various observations to jsonlines files in the
117
127
``.hypothesis/observed/`` directory. You can load and explore these with e.g.
If you are experiencing a significant slow-down, you can try setting
125
-
``HYPOTHESIS_EXPERIMENTAL_OBSERVABILITY_NOCOVER`` instead; this will disable coverage information
126
-
collection. This should not be necessary on Python 3.12 or later, where coverage collection is very fast.
127
-
128
-
129
134
Collecting more information
130
135
^^^^^^^^^^^^^^^^^^^^^^^^^^^
131
136
@@ -181,7 +186,7 @@ While the observability format is agnostic to the property-based testing library
181
186
Choices metadata
182
187
++++++++++++++++
183
188
184
-
These additional metadata elements are included in ``metadata`` (as e.g. ``metadata["choice_nodes"]`` or ``metadata["choice_spans"]``), if and only if |OBSERVABILITY_CHOICES| is set.
189
+
These additional metadata elements are included in ``metadata`` (as e.g. ``metadata["choice_nodes"]`` or ``metadata["choice_spans"]``), if and only if observability is configured to include choices (see :ref:`observability-configuration`).
Copy file name to clipboardExpand all lines: hypothesis-python/docs/reference/schema_metadata_choices.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
"properties": {
4
4
"choice_nodes": {
5
5
"type": ["array", "null"],
6
-
"description": ".. warning::\n\n EXPERIMENTAL AND UNSTABLE. This attribute may change format or disappear without warning.\n\nThe sequence of choices made during this test case. This includes the choice value, as well as its constraints and whether it was forced or not.\n\nOnly present if |OBSERVABILITY_CHOICES| is ``True``.\n\n.. note::\n\n The choice sequence is a relatively low-level implementation detail of Hypothesis, and is exposed in observability for users building tools or research on top of Hypothesis. See |PrimitiveProvider| for more details about the choice sequence.",
6
+
"description": ".. warning::\n\n EXPERIMENTAL AND UNSTABLE. This attribute may change format without warning.\n\nThe sequence of choices made during this test case. This includes the choice value, as well as its constraints and whether it was forced or not.\n\n.. note::\n\n Only present if observability is configured to include choices (see :ref:`observability-configuration`).\n\n.. note::\n\n The choice sequence is a relatively low-level implementation detail of Hypothesis, and is exposed in observability for users building tools or research on top of Hypothesis. See |PrimitiveProvider| for more details about the choice sequence.",
7
7
"items": {
8
8
"type": "object",
9
9
"properties": {
@@ -31,7 +31,7 @@
31
31
"choice_spans": {
32
32
"type": "array",
33
33
"items": {"type": "array"},
34
-
"description": ".. warning::\n\n EXPERIMENTAL AND UNSTABLE. This attribute may change format or disappear without warning.\n\nThe semantically-meaningful spans of the choice sequence of this test case.\n\nEach span has the format ``[label, start, end, discarded]``, where:\n\n* ``label`` is an opaque integer-value string shared by all spans drawn from a particular strategy.\n* ``start`` and ``end`` are indices into the choice sequence for this span, such that ``choices[start:end]`` are the corresponding choices.\n* ``discarded`` is a boolean indicating whether this span was discarded (see |PrimitiveProvider.span_end|).\n\nOnly present if |OBSERVABILITY_CHOICES| is ``True``.\n\n.. note::\n\n Spans are a relatively low-level implementation detail of Hypothesis, and are exposed in observability for users building tools or research on top of Hypothesis. See |PrimitiveProvider| (and particularly |PrimitiveProvider.span_start| and |PrimitiveProvider.span_end|) for more details about spans."
34
+
"description": ".. warning::\n\n EXPERIMENTAL AND UNSTABLE. This attribute may change format without warning.\n\nThe semantically-meaningful spans of the choice sequence of this test case.\n\nEach span has the format ``[label, start, end, discarded]``, where:\n\n* ``label`` is an opaque integer-value string shared by all spans drawn from a particular strategy.\n* ``start`` and ``end`` are indices into the choice sequence for this span, such that ``choices[start:end]`` are the corresponding choices.\n* ``discarded`` is a boolean indicating whether this span was discarded (see |PrimitiveProvider.span_end|).\n\n.. note::\n\n Only present if observability is configured to include choices (see :ref:`observability-configuration`).\n\n.. note::\n\n Spans are a relatively low-level implementation detail of Hypothesis, and are exposed in observability for users building tools or research on top of Hypothesis. See |PrimitiveProvider| (and particularly |PrimitiveProvider.span_start| and |PrimitiveProvider.span_end|) for more details about spans."
Copy file name to clipboardExpand all lines: hypothesis-python/docs/reference/schema_observations.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@
36
36
},
37
37
"coverage": {
38
38
"type": ["object", "null"],
39
-
"description": "Mapping of filename to list of covered line numbers, if coverage information is available, or None if not. Hypothesis deliberately omits stdlib and site-packages code.",
39
+
"description": "Mapping of filename to list of covered line numbers, if coverage information is available, or None if not. Hypothesis deliberately omits stdlib and site-packages code.\n\n.. note::\n\n Only present if observability is configured to include coverage (see :ref:`observability-configuration`).",
0 commit comments