Merge pull request #4399 from blueyed/summary

Display "short test summary info" after (main) warnings again
This commit is contained in:
Bruno Oliveira 2018-11-23 18:06:40 -02:00 committed by GitHub
commit 23e4447922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View File

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

View File

@ -647,9 +647,11 @@ class TerminalReporter(object):
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)
@ -726,11 +728,19 @@ class TerminalReporter(object):
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

View File

@ -1074,11 +1074,27 @@ def test_terminal_summary_warnings_are_displayed(testdir):
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(