Skip to content

Commit

Permalink
nodes: fix tracebacks from collection errors are not getting pruned
Browse files Browse the repository at this point in the history
  • Loading branch information
bluetech committed Dec 16, 2023
1 parent 047ba83 commit 7706286
Show file tree
Hide file tree
Showing 3 changed files with 26 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 @@ -579,7 +579,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
24 changes: 24 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from _pytest.pathlib import symlink_or_skip
from _pytest.pytester import HookRecorder
from _pytest.pytester import Pytester
from _pytest._code.code import ExceptionChainRepr, ReprTraceback


def ensure_file(file_path: Path) -> Path:
Expand Down Expand Up @@ -345,6 +346,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 7706286

Please sign in to comment.