Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.4.x] nodes: fix tracebacks from collection errors are not getting pruned #11747

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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