Skip to content

Commit

Permalink
Move message to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jun 9, 2021
1 parent 670c3e6 commit 8fbdc0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
6 changes: 4 additions & 2 deletions hypothesis-python/src/hypothesis/internal/scrutineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def get_explaining_locations(traces):
"Explanation:",
" These lines were always and only run by failing examples:",
)
HAD_TRACE = " We didn't try to explain this, because sys.gettrace()="


def make_report(explanations, cap_lines_at=5):
Expand All @@ -114,8 +115,9 @@ def make_report(explanations, cap_lines_at=5):

def explanatory_lines(traces, settings):
if Phase.explain in settings.phases and sys.gettrace() and not traces:
msg = " We didn't try to explain this, because sys.gettrace()="
return defaultdict(lambda: [EXPLANATION_STUB[0], msg + repr(sys.gettrace())])
return defaultdict(
lambda: [EXPLANATION_STUB[0], HAD_TRACE + repr(sys.gettrace())]
)
# Return human-readable report lines summarising the traces
explanations = get_explaining_locations(traces)
max_lines = 5 if settings.verbosity <= Verbosity.normal else 100
Expand Down
11 changes: 3 additions & 8 deletions hypothesis-python/tests/cover/test_scrutineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pytest

from hypothesis.internal.compat import PYPY
from hypothesis.internal.scrutineer import make_report
from hypothesis.internal.scrutineer import HAD_TRACE, make_report

BUG_MARKER = "# BUG"
PRELUDE = """
Expand Down Expand Up @@ -88,13 +88,8 @@ def test_cannot_explain_message(testdir):

code = PRELUDE + TRIVIAL
test_file = testdir.makepyfile(code)
result = testdir.runpytest_inprocess(test_file, "--tb=native")
result.stdout.re_match_lines(
[
r"Explanation:",
fr"""\s*{re.escape("We didn't try to explain this, because sys.gettrace()=")}.*""",
],
consecutive=True,
testdir.runpytest_inprocess(test_file, "--tb=native").stdout.re_match_lines(
[r"Explanation:", re.escape(HAD_TRACE)], consecutive=True
)
finally:
if no_tracer:
Expand Down

0 comments on commit 8fbdc0c

Please sign in to comment.