Skip to content

Commit 486537d

Browse files
committed
match against site-packages before stdlib
1 parent a24c3e5 commit 486537d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

hypothesis-python/RELEASE.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
RELEASE_TYPE: patch
22

3-
When reporting the always-passing, never-failing lines from the |Phase.explain| phase, we now sort the reported lines so that local code shows up first, then third-party library code, then standard library code.
3+
When reporting the always-failing, never-passing lines from the |Phase.explain| phase, we now sort the reported lines so that local code shows up first, then third-party library code, then standard library code.

hypothesis-python/src/hypothesis/internal/scrutineer.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,15 @@ def get_explaining_locations(traces):
232232

233233

234234
# show local files first, then site-packages, then stdlib
235-
def _sort_key(fname, lineno):
236-
fname = Path(fname).resolve()
237-
if any(fname.is_relative_to(p) for p in STDLIB_DIRS):
238-
return (2, fname, lineno)
239-
if any(fname.is_relative_to(p) for p in SITE_PACKAGES_DIRS):
240-
return (1, fname, lineno)
241-
return (0, fname, lineno)
235+
def _sort_key(path, lineno):
236+
path = Path(path).resolve()
237+
# site-packages may be a subdir of stdlib or platlib, so it's important to
238+
# check is_relative_to for this before the stdlib.
239+
if any(path.is_relative_to(p) for p in SITE_PACKAGES_DIRS):
240+
return (1, path, lineno)
241+
if any(path.is_relative_to(p) for p in STDLIB_DIRS):
242+
return (2, path, lineno)
243+
return (0, path, lineno)
242244

243245

244246
def make_report(explanations, *, cap_lines_at=5):

hypothesis-python/tests/nocover/test_scrutineer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def test_report_sort(random):
127127
(json.__file__, 42),
128128
]
129129
random.shuffle(lines)
130-
explanations = {"origin1": lines}
130+
explanations = {"origin": lines}
131131
report = make_report(explanations)
132-
report_lines = report["origin1"][2:]
132+
report_lines = report["origin"][2:]
133133
report_lines = [line.strip() for line in report_lines]
134134

135135
expected_lines = [

0 commit comments

Comments
 (0)