Skip to content
Open
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 AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ Terje Runde
Thomas Grainger
Thomas Hisch
Tianyu Dongfang
Tim Anderson
Tim Hoffmann
Tim Strazny
TJ Bruno
Expand Down
2 changes: 2 additions & 0 deletions changelog/14902.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Disambiguated terminal report headings for tests with the same name by including
their node IDs when needed.
12 changes: 11 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,13 @@ def summary_failures_combined(
self._outrep_summary(rep)
self.write_line(line)
else:
headline_counts = Counter(
self._getfailureheadline(rep) for rep in reports
)
for rep in reports:
msg = self._getfailureheadline(rep)
if headline_counts[msg] > 1:
msg = self.config.cwd_relative_nodeid(rep.nodeid) or msg
self.write_sep("_", msg, red=True, bold=True)
self._outrep_summary(rep)
self._handle_teardown_sections(rep.nodeid)
Expand All @@ -1245,8 +1250,13 @@ def summary_errors(self) -> None:
if not reports:
return
self.write_sep("=", "ERRORS")
for rep in self.stats["error"]:
headline_counts = Counter(
(rep.when, self._getfailureheadline(rep)) for rep in reports
)
for rep in reports:
msg = self._getfailureheadline(rep)
if headline_counts[rep.when, msg] > 1:
msg = self.config.cwd_relative_nodeid(rep.nodeid) or msg
if rep.when == "collect":
msg = "ERROR collecting " + msg
else:
Expand Down
55 changes: 55 additions & 0 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,61 @@ def test_bar(): pass


class TestFixtureReporting:
def test_duplicate_setup_error_headlines_are_disambiguated(
self, pytester: Pytester
) -> None:
pytester.makeconftest(
"""
import pytest

@pytest.fixture
def fixture():
raise RuntimeError("fixture failed")
"""
)
pytester.makepyfile(
test_1="""
def test(fixture):
pass
""",
test_2="""
def test(fixture):
pass
""",
)

result = pytester.runpytest("-q")

result.stdout.fnmatch_lines(
[
"*ERROR at setup of test_1.py::test*",
"*ERROR at setup of test_2.py::test*",
]
)

def test_duplicate_failure_headlines_are_disambiguated(
self, pytester: Pytester
) -> None:
pytester.makepyfile(
test_1="""
def test():
assert False
""",
test_2="""
def test():
assert False
""",
)

result = pytester.runpytest("-q")

result.stdout.fnmatch_lines(
[
"*_ test_1.py::test _*",
"*_ test_2.py::test _*",
]
)

def test_setup_fixture_error(self, pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down