-
Notifications
You must be signed in to change notification settings - Fork 626
Stabilize observability #4563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Stabilize observability #4563
Changes from all commits
4eb82da
206250f
e881408
ecc3fd6
89bff3f
310825d
daf1d23
9e9793f
0c1c08b
bad47bf
ac261c1
a5fab00
0aa7b72
ae7ac47
d7a20a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| RELEASE_TYPE: minor | ||
|
|
||
| This release adds |settings.observability|, which can be used to enable :ref:`observability <observability>`. | ||
|
|
||
| When observability is enabled, Hypothesis writes data about each test case to the ``.hypothesis/observed`` directory in an analysis-ready `jsonlines <https://jsonlines.org/>`_ format. This data is intended to help users who want to dive deep into understanding their tests. It's also intended for people building tools or research on top of Hypothesis. | ||
|
|
||
| Observability can be controlled in two ways: | ||
|
|
||
| * via the new |settings.observability| argument, | ||
| * or via the ``HYPOTHESIS_OBSERVABILITY`` environment variable. | ||
|
|
||
| See :ref:`Configuring observability <observability-configuration>` for details. | ||
|
|
||
| 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. |
| 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`_! | |
| Observability | ||
| ------------- | ||
|
|
||
| .. note:: | ||
| .. tip:: | ||
|
|
||
| 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. | ||
|
|
||
| .. warning:: | ||
|
|
||
| This feature is experimental, and could have breaking changes or even be removed | ||
| without notice. Try it out, let us know what you think, but don't rely on it | ||
| just yet! | ||
|
|
||
|
|
||
| Motivation | ||
| ~~~~~~~~~~ | ||
|
|
||
|
|
@@ -108,24 +101,23 @@ debuggers such as `rr <https://rr-project.org/>`__ or `pytrace <https://pytrace. | |
| because there's no good way to compare multiple traces from these tools and their | ||
| Python support is relatively immature. | ||
|
|
||
| .. _observability-configuration: | ||
|
|
||
| Configuration | ||
| ~~~~~~~~~~~~~ | ||
| Configuring observability | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| If you set the ``HYPOTHESIS_EXPERIMENTAL_OBSERVABILITY`` environment variable, | ||
| Hypothesis will log various observations to jsonlines files in the | ||
| The standard way to configure observability is with |settings.observability|. | ||
|
|
||
| Alternatively, observability can be configured by setting the ``HYPOTHESIS_OBSERVABILITY`` environment variable. If ``HYPOTHESIS_OBSERVABILITY`` is set to one of ``True``, ``true``, or ``1``, |settings.observability| defaults to ``True``. Note that unlike |settings.observability|, ``HYPOTHESIS_OBSERVABILITY`` only configures whether observability is enabled or disabled, not additional options like |ObservabilityConfig|. | ||
|
|
||
| When observability is enabled, Hypothesis will log various observations to jsonlines files in the | ||
| ``.hypothesis/observed/`` directory. You can load and explore these with e.g. | ||
| :func:`pd.read_json(".hypothesis/observed/*_testcases.jsonl", lines=True) <pandas.read_json>`, | ||
| or by using the :pypi:`sqlite-utils` and :pypi:`datasette` libraries:: | ||
|
|
||
| sqlite-utils insert testcases.db testcases .hypothesis/observed/*_testcases.jsonl --nl --flatten | ||
| datasette serve testcases.db | ||
|
|
||
| If you are experiencing a significant slow-down, you can try setting | ||
| ``HYPOTHESIS_EXPERIMENTAL_OBSERVABILITY_NOCOVER`` instead; this will disable coverage information | ||
| collection. This should not be necessary on Python 3.12 or later, where coverage collection is very fast. | ||
|
|
||
|
|
||
| Collecting more information | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
|
|
@@ -181,7 +173,7 @@ While the observability format is agnostic to the property-based testing library | |
| Choices metadata | ||
| ++++++++++++++++ | ||
|
|
||
| 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. | ||
| 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 |ObservabilityConfig|). | ||
|
Comment on lines
173
to
+176
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want a similar heading for Coverage metadata, now that it's off by default? And also note that the format of that is unstable, since we might want to switch representations |
||
|
|
||
| .. jsonschema:: ./schema_metadata_choices.json | ||
| :hide_key: /additionalProperties, /type | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,15 +30,8 @@ Alternative backends | |
| Observability | ||
| ------------- | ||
|
|
||
| .. autofunction:: hypothesis.internal.observability.add_observability_callback | ||
| .. autofunction:: hypothesis.internal.observability.remove_observability_callback | ||
| .. autofunction:: hypothesis.internal.observability.with_observability_callback | ||
| .. autofunction:: hypothesis.internal.observability.observability_enabled | ||
|
Comment on lines
30
to
33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| .. autodata:: hypothesis.internal.observability.TESTCASE_CALLBACKS | ||
| .. autodata:: hypothesis.internal.observability.OBSERVABILITY_COLLECT_COVERAGE | ||
| .. autodata:: hypothesis.internal.observability.OBSERVABILITY_CHOICES | ||
|
|
||
| Engine constants | ||
| ---------------- | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to note that callbacks can be customized / this is the default only.