Skip to content

Commit

Permalink
Merge pull request #3746 from Zac-HD/enable-explain-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD authored Sep 17, 2023
2 parents 03d8312 + c419bc5 commit 3c73294
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RELEASE_TYPE: minor

This release enables the :obj:`~hypothesis.Phase.explain` :ref:`phase <phases>`
by default. We hope it helps you to understand _why_ your failing tests have
failed!
4 changes: 1 addition & 3 deletions hypothesis-python/src/hypothesis/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,7 @@ def _validate_phases(phases):

settings._define_setting(
"phases",
# We leave the `explain` phase disabled by default, for speed and brevity
# TODO: consider default-enabling this in CI?
default=_validate_phases(set(Phase) - {Phase.explain}),
default=tuple(Phase),
description=(
"Control which phases should be run. "
"See :ref:`the full documentation for more details <phases>`"
Expand Down
3 changes: 2 additions & 1 deletion hypothesis-python/src/hypothesis/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import math
from collections import Counter

from hypothesis._settings import Phase
from hypothesis.utils.dynamicvariables import DynamicVariable

collector = DynamicVariable(None)
Expand Down Expand Up @@ -73,7 +74,7 @@ def describe_statistics(stats_dict):
"""
lines = [stats_dict["nodeid"] + ":\n"] if "nodeid" in stats_dict else []
prev_failures = 0
for phase in ["reuse", "generate", "shrink"]:
for phase in (p.name for p in list(Phase)[1:]):
d = stats_dict.get(phase + "-phase", {})
# Basic information we report for every phase
cases = d.get("test-cases", [])
Expand Down
4 changes: 2 additions & 2 deletions hypothesis-python/tests/cover/test_phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_sorts_and_dedupes_phases(arg, expected):
assert settings(phases=arg).phases == expected


def test_phases_default_to_all_except_explain():
assert (*all_settings["phases"].default, Phase.explain) == tuple(Phase)
def test_phases_default_to_all():
assert all_settings["phases"].default == tuple(Phase)


def test_does_not_reuse_saved_examples_if_reuse_not_in_phases():
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/tests/cover/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def __repr__(self):


def test_show_changed():
s = settings(max_examples=999, database=None, phases=tuple(Phase)[:-1])
s = settings(max_examples=999, database=None)
assert s.show_changed() == "database=None, max_examples=999"


Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/tests/cover/test_statistical_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def threshold(error):


def test_statistics_with_events_and_target():
@given(st.sampled_from("1234"))
@given(st.integers(0, 10_000))
def test(value):
event(value)
target(float(value), label="a target")
Expand Down

0 comments on commit 3c73294

Please sign in to comment.