Skip to content

Commit

Permalink
Display "short test summary info" after (main) warnings again
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Nov 23, 2018
1 parent 0b73d6d commit 0cf45ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/3952.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Display warnings before "short test summary info" again, but still later warnings in the end.
16 changes: 13 additions & 3 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,11 @@ def pytest_sessionfinish(self, exitstatus):
def pytest_terminal_summary(self):
self.summary_errors()
self.summary_failures()
yield
self.summary_warnings()
yield
self.summary_passes()
# Display any extra warnings from teardown here (if any).
self.summary_warnings()

def pytest_keyboard_interrupt(self, excinfo):
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
Expand Down Expand Up @@ -726,11 +728,19 @@ def summary_warnings(self):
if not all_warnings:
return

final = hasattr(self, "_already_displayed_warnings")
if final:
warnings = all_warnings[self._already_displayed_warnings :]
else:
warnings = all_warnings
self._already_displayed_warnings = len(warnings)

grouped = itertools.groupby(
all_warnings, key=lambda wr: wr.get_location(self.config)
warnings, key=lambda wr: wr.get_location(self.config)
)

self.write_sep("=", "warnings summary", yellow=True, bold=False)
title = "warnings summary (final)" if final else "warnings summary"
self.write_sep("=", title, yellow=True, bold=False)
for location, warning_records in grouped:
# legacy warnings show their location explicitly, while standard warnings look better without
# it because the location is already formatted into the message
Expand Down
20 changes: 18 additions & 2 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,27 @@ def pytest_terminal_summary(terminalreporter):
warnings.warn(UserWarning('internal warning'))
"""
)
result = testdir.runpytest()
testdir.makepyfile(
"""
def test_failure():
import warnings
warnings.warn("warning_from_" + "test")
assert 0
"""
)
result = testdir.runpytest("-ra")
result.stdout.fnmatch_lines(
["*conftest.py:3:*internal warning", "*== 1 warnings in *"]
[
"*= warnings summary =*",
"*warning_from_test*",
"*= short test summary info =*",
"*= warnings summary (final) =*",
"*conftest.py:3:*internal warning",
"*== 1 failed, 2 warnings in *",
]
)
assert "None" not in result.stdout.str()
assert result.stdout.str().count("warning_from_test") == 1


@pytest.mark.parametrize(
Expand Down

0 comments on commit 0cf45ee

Please sign in to comment.