Skip to content

Commit

Permalink
Merge pull request #11747 from pytest-dev/backport-11711-to-7.4.x
Browse files Browse the repository at this point in the history
[7.4.x] nodes: fix tracebacks from collection errors are not getting pruned
  • Loading branch information
bluetech authored Dec 31, 2023
2 parents 5582bfc + d06c05b commit 2cdd619
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/11710.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed tracebacks from collection errors not getting pruned.
2 changes: 1 addition & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback:
ntraceback = traceback.cut(path=self.path)
if ntraceback == traceback:
ntraceback = ntraceback.cut(excludepath=tracebackcutdir)
return excinfo.traceback.filter(excinfo)
return ntraceback.filter(excinfo)
return excinfo.traceback


Expand Down
23 changes: 23 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,29 @@ def pytest_make_collect_report():
result = pytester.runpytest(p)
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:
def test_ignore_collect_path(self, pytester: Pytester) -> None:
Expand Down

0 comments on commit 2cdd619

Please sign in to comment.