Skip to content

Commit

Permalink
Disable explain mode for DeadlineExceeded
Browse files Browse the repository at this point in the history
For two reasons: our analysis is just not relevant to deadline exceeded failures, and running under a tracer adds some non-representative slowdowns.

Note that this code handles the case where we first discover an unrelated bug, start shrinking, and then find a deadline-exceeding input.
  • Loading branch information
Zac-HD committed Jun 9, 2021
1 parent 2a142be commit c1d3ccf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def __init__(

self.files_to_propagate = set()
self.failed_normally = False
self.failed_due_to_deadline = False

self.explain_traces = defaultdict(set)

Expand Down Expand Up @@ -668,6 +669,7 @@ def _execute_once_for_engine(self, data):
trace = frozenset()
if (
self.failed_normally
and not self.failed_due_to_deadline
and Phase.explain in self.settings.phases
and sys.gettrace() is None
and not PYPY
Expand Down Expand Up @@ -736,6 +738,9 @@ def _execute_once_for_engine(self, data):
if trace: # pragma: no cover
# Trace collection is explicitly disabled under coverage.
self.explain_traces[interesting_origin].add(trace)
if interesting_origin[0] == DeadlineExceeded:
self.failed_due_to_deadline = True
self.explain_traces.clear()
data.mark_interesting(interesting_origin)

def run_engine(self):
Expand Down
11 changes: 11 additions & 0 deletions hypothesis-python/tests/nocover/test_scrutineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
pytestmark = pytest.mark.skipif(PYPY or sys.gettrace(), reason="See comment")

BUG_MARKER = "# BUG"
DEADLINE_PRELUDE = """
from datetime import timedelta
from hypothesis.errors import DeadlineExceeded
"""
PRELUDE = """
from hypothesis import Phase, given, settings, strategies as st
Expand Down Expand Up @@ -70,3 +74,10 @@ def test_explanations(code, testdir):
assert len(expected) == code.count(BUG_MARKER)
for report in expected:
assert report in pytest_stdout


@pytest.mark.parametrize("code", FRAGMENTS)
def test_no_explanations_if_deadline_exceeded(code, testdir):
code = code.replace("AssertionError", "DeadlineExceeded(timedelta(), timedelta())")
pytest_stdout, _ = get_reports(DEADLINE_PRELUDE + PRELUDE + code, testdir=testdir)
assert "Explanation:" not in pytest_stdout

0 comments on commit c1d3ccf

Please sign in to comment.