-
-
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
Display message from reprcrash in short test summary #5013
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3d0ecd0
Display message from reprcrash in short test summary
blueyed 37ecca3
factor out _get_line_with_reprcrash_message
blueyed 1597044
change separator to hyphen
blueyed f599172
test with 😄 in message
blueyed df377b5
use wcwidth
blueyed 2ebb69b
py2 fixes
blueyed 2b1ae8a
__tracebackhide__ for check
blueyed 14d3d91
Remove partial unicode characters from summary messages in Python 2
nicoddemus df1d110
Merge remote-tracking branch 'origin/features' into short-summary-mes…
blueyed c3178a1
move test
blueyed 0e8a8f9
Add encoding header to test_terminal.py
nicoddemus 32a5e80
Add encoding: header and fix rep mock in test_line_with_reprcrash on …
nicoddemus c04767f
Use msg.rstrip() as suggested in review
nicoddemus f339147
Add CHANGELOG entry about depending on wcwidth
nicoddemus 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 @@ | ||
Messages from crash reports are displayed within test summaries now, truncated to the terminal width. |
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 @@ | ||
pytest now depends on `wcwidth <https://pypi.org/project/wcwidth>`__ to properly track unicode character sizes for more precise terminal output. | ||
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# encoding: utf-8 | ||
""" terminal reporting of the full testing process. | ||
|
||
This is a good source for looking at the various reporting hooks. | ||
|
@@ -889,10 +890,13 @@ def short_test_summary(self): | |
|
||
def show_simple(stat, lines): | ||
failed = self.stats.get(stat, []) | ||
if not failed: | ||
return | ||
termwidth = self.writer.fullwidth | ||
config = self.config | ||
for rep in failed: | ||
verbose_word = rep._get_verbose_word(self.config) | ||
pos = _get_pos(self.config, rep) | ||
lines.append("%s %s" % (verbose_word, pos)) | ||
line = _get_line_with_reprcrash_message(config, rep, termwidth) | ||
lines.append(line) | ||
|
||
def show_xfailed(lines): | ||
xfailed = self.stats.get("xfailed", []) | ||
|
@@ -929,10 +933,6 @@ def show_skipped(lines): | |
else: | ||
lines.append("%s [%d] %s: %s" % (verbose_word, num, fspath, reason)) | ||
|
||
def _get_pos(config, rep): | ||
nodeid = config.cwd_relative_nodeid(rep.nodeid) | ||
return nodeid | ||
|
||
REPORTCHAR_ACTIONS = { | ||
"x": show_xfailed, | ||
"X": show_xpassed, | ||
|
@@ -956,6 +956,56 @@ def _get_pos(config, rep): | |
self.write_line(line) | ||
|
||
|
||
def _get_pos(config, rep): | ||
nodeid = config.cwd_relative_nodeid(rep.nodeid) | ||
return nodeid | ||
|
||
|
||
def _get_line_with_reprcrash_message(config, rep, termwidth): | ||
"""Get summary line for a report, trying to add reprcrash message.""" | ||
from wcwidth import wcswidth | ||
|
||
verbose_word = rep._get_verbose_word(config) | ||
pos = _get_pos(config, rep) | ||
|
||
line = "%s %s" % (verbose_word, pos) | ||
len_line = wcswidth(line) | ||
ellipsis, len_ellipsis = "...", 3 | ||
if len_line > termwidth - len_ellipsis: | ||
# No space for an additional message. | ||
return line | ||
|
||
try: | ||
msg = rep.longrepr.reprcrash.message | ||
except AttributeError: | ||
pass | ||
else: | ||
# Only use the first line. | ||
i = msg.find("\n") | ||
if i != -1: | ||
msg = msg[:i] | ||
len_msg = wcswidth(msg) | ||
|
||
sep, len_sep = " - ", 3 | ||
max_len_msg = termwidth - len_line - len_sep | ||
if max_len_msg >= len_ellipsis: | ||
if len_msg > max_len_msg: | ||
max_len_msg -= len_ellipsis | ||
msg = msg[:max_len_msg] | ||
while wcswidth(msg) > max_len_msg: | ||
msg = msg[:-1] | ||
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. Said this earlier already, but this could certainly be done better, e.g. by using |
||
if six.PY2: | ||
# on python 2 systems with narrow unicode compilation, trying to | ||
# get a single character out of a multi-byte unicode character such as | ||
# u'😄' will result in a High Surrogate (U+D83D) character, which is | ||
# rendered as u'�'; in this case we just strip that character out as it | ||
# serves no purpose being rendered | ||
msg = msg.rstrip(u"\uD83D") | ||
msg += ellipsis | ||
line += sep + msg | ||
return line | ||
|
||
|
||
def _folded_skips(skipped): | ||
d = {} | ||
for event in skipped: | ||
|
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
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! ❤️