-
-
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
Changes from 5 commits
3d0ecd0
37ecca3
1597044
f599172
df377b5
2ebb69b
2b1ae8a
14d3d91
df1d110
c3178a1
0e8a8f9
32a5e80
c04767f
f339147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,14 +204,52 @@ def pytest_terminal_summary(terminalreporter): | |
tr._tw.line(line) | ||
|
||
|
||
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 = _get_report_str(config, rep) | ||
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] | ||
msg += ellipsis | ||
line += sep + msg | ||
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. Oh just realized this: is 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. Would appreciate a failing example.. do you mean we should prefix 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. Hmm actually no, this is safe: if 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. If you want to play it safe and ensure we don't regress though, you can change the message to use a smiling face emoji instead (😄), but is up to you. 👍 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. Added.. but it shows that we're not handling terminal cells there really - i.e. it would wrap due to this. 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. Oh. Hmm not even sure what the solution would be, TBH. 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. added a commit using wcwidth.. not sure if it is worth the extra dependency, but it worked well.. ;) 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. I think adding |
||
return line | ||
|
||
|
||
def show_simple(terminalreporter, lines, stat): | ||
failed = terminalreporter.stats.get(stat) | ||
if failed: | ||
config = terminalreporter.config | ||
termwidth = terminalreporter.writer.fullwidth | ||
for rep in failed: | ||
verbose_word = _get_report_str(config, rep) | ||
pos = _get_pos(config, rep) | ||
lines.append("%s %s" % (verbose_word, pos)) | ||
line = _get_line_with_reprcrash_message(config, rep, termwidth) | ||
lines.append(line) | ||
|
||
|
||
def show_xfailed(terminalreporter, lines): | ||
|
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.
This could be optimized probably if we're taking it - there is also
wcwidth
.