nodes: fix tracebacks from collection errors are not getting pruned (#11711)

Fix #11710.
This commit is contained in:
Ran Benita 2023-12-31 10:14:23 +02:00 committed by GitHub
parent 640f84a5aa
commit d220880924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1 @@
Fixed tracebacks from collection errors not getting pruned.

View File

@ -579,7 +579,7 @@ class Collector(Node, abc.ABC):
ntraceback = traceback.cut(path=self.path) ntraceback = traceback.cut(path=self.path)
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=tracebackcutdir) ntraceback = ntraceback.cut(excludepath=tracebackcutdir)
return excinfo.traceback.filter(excinfo) return ntraceback.filter(excinfo)
return excinfo.traceback return excinfo.traceback

View File

@ -345,6 +345,29 @@ class TestPrunetraceback:
result = pytester.runpytest(p) result = pytester.runpytest(p)
result.stdout.fnmatch_lines(["*ERROR collecting*", "*header1*"]) result.stdout.fnmatch_lines(["*ERROR collecting*", "*header1*"])
def test_collection_error_traceback_is_clean(self, pytester: Pytester) -> None:
"""When a collection error occurs, the report traceback doesn't contain
internal pytest stack entries.
Issue #11710.
"""
pytester.makepyfile(
"""
raise Exception("LOUSY")
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
[
"*ERROR collecting*",
"test_*.py:1: in <module>",
' raise Exception("LOUSY")',
"E Exception: LOUSY",
"*= short test summary info =*",
],
consecutive=True,
)
class TestCustomConftests: class TestCustomConftests:
def test_ignore_collect_path(self, pytester: Pytester) -> None: def test_ignore_collect_path(self, pytester: Pytester) -> None: