Skip to content

Commit 4cf20aa

Browse files
committed
Display "short test summary info" after (main) warnings again
Fixes pytest-dev#3952.
1 parent 9dec146 commit 4cf20aa

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

changelog/3952.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Display warnings before "short test summary info" again, but still later warnings in the end.

src/_pytest/terminal.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,10 @@ def pytest_sessionfinish(self, exitstatus):
647647
def pytest_terminal_summary(self):
648648
self.summary_errors()
649649
self.summary_failures()
650-
yield
651650
self.summary_warnings()
651+
yield
652652
self.summary_passes()
653+
self.summary_warnings()
653654

654655
def pytest_keyboard_interrupt(self, excinfo):
655656
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
@@ -726,11 +727,19 @@ def summary_warnings(self):
726727
if not all_warnings:
727728
return
728729

730+
final = hasattr(self, "_already_displayed_warnings")
731+
if final:
732+
warnings = all_warnings[self._already_displayed_warnings :]
733+
else:
734+
warnings = all_warnings
735+
self._already_displayed_warnings = len(warnings)
736+
729737
grouped = itertools.groupby(
730-
all_warnings, key=lambda wr: wr.get_location(self.config)
738+
warnings, key=lambda wr: wr.get_location(self.config)
731739
)
732740

733-
self.write_sep("=", "warnings summary", yellow=True, bold=False)
741+
title = "warnings summary (final)" if final else "warnings summary"
742+
self.write_sep("=", title, yellow=True, bold=False)
734743
for location, warning_records in grouped:
735744
# legacy warnings show their location explicitly, while standard warnings look better without
736745
# it because the location is already formatted into the message

testing/test_terminal.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1074,11 +1074,27 @@ def pytest_terminal_summary(terminalreporter):
10741074
warnings.warn(UserWarning('internal warning'))
10751075
"""
10761076
)
1077-
result = testdir.runpytest()
1077+
testdir.makepyfile(
1078+
"""
1079+
def test_failure():
1080+
import warnings
1081+
warnings.warn("warning_from_" + "test")
1082+
assert 0
1083+
"""
1084+
)
1085+
result = testdir.runpytest("-ra")
10781086
result.stdout.fnmatch_lines(
1079-
["*conftest.py:3:*internal warning", "*== 1 warnings in *"]
1087+
[
1088+
"*= warnings summary =*",
1089+
"*warning_from_test*",
1090+
"*= short test summary info =*",
1091+
"*= warnings summary (final) =*",
1092+
"*conftest.py:3:*internal warning",
1093+
"*== 1 failed, 2 warnings in *",
1094+
]
10801095
)
10811096
assert "None" not in result.stdout.str()
1097+
assert result.stdout.str().count("warning_from_test") == 1
10821098

10831099

10841100
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)