Skip to content

Commit

Permalink
[7.4.x] nodes: fix tracebacks from collection errors are not getting …
Browse files Browse the repository at this point in the history
…pruned
  • Loading branch information
bluetech authored and pytestbot committed Dec 31, 2023
1 parent 5582bfc commit d06c05b
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)

Check warning on line 570 in src/_pytest/nodes.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/nodes.py#L570

Added line #L570 was not covered by tests
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 d06c05b

Please sign in to comment.