Skip to content

Commit d220880

Browse files
authoredDec 31, 2023
nodes: fix tracebacks from collection errors are not getting pruned (#11711)
Fix #11710.
1 parent 640f84a commit d220880

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
 

‎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.

‎src/_pytest/nodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
579579
ntraceback = traceback.cut(path=self.path)
580580
if ntraceback == traceback:
581581
ntraceback = ntraceback.cut(excludepath=tracebackcutdir)
582-
return excinfo.traceback.filter(excinfo)
582+
return ntraceback.filter(excinfo)
583583
return excinfo.traceback
584584

585585

‎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)
Please sign in to comment.