Skip to content

Commit 2cdd619

Browse files
authored
Merge pull request #11747 from pytest-dev/backport-11711-to-7.4.x
[7.4.x] nodes: fix tracebacks from collection errors are not getting pruned
2 parents 5582bfc + d06c05b commit 2cdd619

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Diff for: changelog/11710.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed tracebacks from collection errors not getting pruned.

Diff for: src/_pytest/nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
567567
ntraceback = traceback.cut(path=self.path)
568568
if ntraceback == traceback:
569569
ntraceback = ntraceback.cut(excludepath=tracebackcutdir)
570-
return excinfo.traceback.filter(excinfo)
570+
return ntraceback.filter(excinfo)
571571
return excinfo.traceback
572572

573573

Diff for: testing/test_collection.py

+23
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,29 @@ def pytest_make_collect_report():
345345
result = pytester.runpytest(p)
346346
result.stdout.fnmatch_lines(["*ERROR collecting*", "*header1*"])
347347

348+
def test_collection_error_traceback_is_clean(self, pytester: Pytester) -> None:
349+
"""When a collection error occurs, the report traceback doesn't contain
350+
internal pytest stack entries.
351+
352+
Issue #11710.
353+
"""
354+
pytester.makepyfile(
355+
"""
356+
raise Exception("LOUSY")
357+
"""
358+
)
359+
result = pytester.runpytest()
360+
result.stdout.fnmatch_lines(
361+
[
362+
"*ERROR collecting*",
363+
"test_*.py:1: in <module>",
364+
' raise Exception("LOUSY")',
365+
"E Exception: LOUSY",
366+
"*= short test summary info =*",
367+
],
368+
consecutive=True,
369+
)
370+
348371

349372
class TestCustomConftests:
350373
def test_ignore_collect_path(self, pytester: Pytester) -> None:

0 commit comments

Comments
 (0)