-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
cleanup: move terminal summary code to terminal plugin #5069
Merged
nicoddemus
merged 5 commits into
pytest-dev:features
from
blueyed:cleanup-summary-to-terminal
Apr 10, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c70ecd4
cleanup: move terminal summary code to terminal plugin
blueyed 06029d1
Refactor into TerminalReporter.short_test_summary
blueyed d8d835c
minor: use functools.partial
blueyed 2662c40
dedent
blueyed dde27a2
changelog [ci skip]
blueyed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The code for the short test summary in the terminal was moved to the terminal plugin. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import platform | ||
import sys | ||
import time | ||
from functools import partial | ||
|
||
import attr | ||
import pluggy | ||
|
@@ -678,6 +679,7 @@ def pytest_terminal_summary(self): | |
self.summary_failures() | ||
self.summary_warnings() | ||
yield | ||
self.short_test_summary() | ||
self.summary_passes() | ||
# Display any extra warnings from teardown here (if any). | ||
self.summary_warnings() | ||
|
@@ -873,6 +875,106 @@ def summary_stats(self): | |
if self.verbosity == -1: | ||
self.write_line(msg, **markup) | ||
|
||
def short_test_summary(self): | ||
if not self.reportchars: | ||
return | ||
|
||
def show_simple(stat, lines): | ||
failed = self.stats.get(stat, []) | ||
for rep in failed: | ||
verbose_word = _get_report_str(self.config, rep) | ||
pos = _get_pos(self.config, rep) | ||
lines.append("%s %s" % (verbose_word, pos)) | ||
|
||
def show_xfailed(lines): | ||
xfailed = self.stats.get("xfailed", []) | ||
for rep in xfailed: | ||
verbose_word = _get_report_str(self.config, rep) | ||
pos = _get_pos(self.config, rep) | ||
lines.append("%s %s" % (verbose_word, pos)) | ||
reason = rep.wasxfail | ||
if reason: | ||
lines.append(" " + str(reason)) | ||
|
||
def show_xpassed(lines): | ||
xpassed = self.stats.get("xpassed", []) | ||
for rep in xpassed: | ||
verbose_word = _get_report_str(self.config, rep) | ||
pos = _get_pos(self.config, rep) | ||
reason = rep.wasxfail | ||
lines.append("%s %s %s" % (verbose_word, pos, reason)) | ||
|
||
def show_skipped(lines): | ||
skipped = self.stats.get("skipped", []) | ||
fskips = _folded_skips(skipped) if skipped else [] | ||
if not fskips: | ||
return | ||
verbose_word = _get_report_str(self.config, report=skipped[0]) | ||
for num, fspath, lineno, reason in fskips: | ||
if reason.startswith("Skipped: "): | ||
reason = reason[9:] | ||
if lineno is not None: | ||
lines.append( | ||
"%s [%d] %s:%d: %s" | ||
% (verbose_word, num, fspath, lineno + 1, reason) | ||
) | ||
else: | ||
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason)) | ||
|
||
def _get_report_str(config, report): | ||
_category, _short, verbose = config.hook.pytest_report_teststatus( | ||
report=report, config=config | ||
) | ||
return verbose | ||
|
||
def _get_pos(config, rep): | ||
nodeid = config.cwd_relative_nodeid(rep.nodeid) | ||
return nodeid | ||
|
||
REPORTCHAR_ACTIONS = { | ||
"x": show_xfailed, | ||
"X": show_xpassed, | ||
"f": partial(show_simple, "failed"), | ||
"F": partial(show_simple, "failed"), | ||
"s": show_skipped, | ||
"S": show_skipped, | ||
"p": partial(show_simple, "passed"), | ||
"E": partial(show_simple, "error"), | ||
} | ||
|
||
lines = [] | ||
for char in self.reportchars: | ||
action = REPORTCHAR_ACTIONS.get(char) | ||
if action: # skipping e.g. "P" (passed with output) here. | ||
action(lines) | ||
|
||
if lines: | ||
self.write_sep("=", "short test summary info") | ||
for line in lines: | ||
self.write_line(line) | ||
|
||
|
||
def _folded_skips(skipped): | ||
d = {} | ||
for event in skipped: | ||
key = event.longrepr | ||
assert len(key) == 3, (event, key) | ||
keywords = getattr(event, "keywords", {}) | ||
# folding reports with global pytestmark variable | ||
# this is workaround, because for now we cannot identify the scope of a skip marker | ||
# TODO: revisit after marks scope would be fixed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RonnyPfannschmidt is now the time to revisit this? |
||
if ( | ||
event.when == "setup" | ||
and "skip" in keywords | ||
and "pytestmark" not in keywords | ||
): | ||
key = (key[0], None, key[2]) | ||
d.setdefault(key, []).append(event) | ||
values = [] | ||
for key, events in d.items(): | ||
values.append((len(events),) + key) | ||
return values | ||
|
||
|
||
def build_summary_stats_line(stats): | ||
known_types = ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome - sounds really trivial after all indeed.. ;)
/me needs to appreciate changelogs more / not getting annoyed by having to add them.. at least
[ci skip]
allows to skip Travis.