35
35
from _pytest import timing
36
36
from _pytest ._code import ExceptionInfo
37
37
from _pytest ._code .code import ExceptionRepr
38
+ from _pytest ._io import TerminalWriter
38
39
from _pytest ._io .wcwidth import wcswidth
39
40
from _pytest .compat import final
40
41
from _pytest .config import _PluggyPlugin
@@ -1074,58 +1075,71 @@ def short_test_summary(self) -> None:
1074
1075
if not self .reportchars :
1075
1076
return
1076
1077
1077
- def show_simple (stat , lines : List [str ]) -> None :
1078
+ def show_simple (lines : List [str ], * , stat : str ) -> None :
1078
1079
failed = self .stats .get (stat , [])
1079
1080
if not failed :
1080
1081
return
1081
- termwidth = self ._tw .fullwidth
1082
1082
config = self .config
1083
1083
for rep in failed :
1084
- line = _get_line_with_reprcrash_message (config , rep , termwidth )
1084
+ color = _color_for_type .get (stat , _color_for_type_default )
1085
+ line = _get_line_with_reprcrash_message (
1086
+ config , rep , self ._tw , {color : True }
1087
+ )
1085
1088
lines .append (line )
1086
1089
1087
1090
def show_xfailed (lines : List [str ]) -> None :
1088
1091
xfailed = self .stats .get ("xfailed" , [])
1089
1092
for rep in xfailed :
1090
1093
verbose_word = rep ._get_verbose_word (self .config )
1091
- pos = _get_pos (self .config , rep )
1092
- lines .append (f"{ verbose_word } { pos } " )
1094
+ markup_word = self ._tw .markup (
1095
+ verbose_word , ** {_color_for_type ["warnings" ]: True }
1096
+ )
1097
+ nodeid = _get_node_id_with_markup (self ._tw , self .config , rep )
1098
+ line = f"{ markup_word } { nodeid } "
1093
1099
reason = rep .wasxfail
1094
1100
if reason :
1095
- lines .append (" " + str (reason ))
1101
+ line += " - " + str (reason )
1102
+
1103
+ lines .append (line )
1096
1104
1097
1105
def show_xpassed (lines : List [str ]) -> None :
1098
1106
xpassed = self .stats .get ("xpassed" , [])
1099
1107
for rep in xpassed :
1100
1108
verbose_word = rep ._get_verbose_word (self .config )
1101
- pos = _get_pos (self .config , rep )
1109
+ markup_word = self ._tw .markup (
1110
+ verbose_word , ** {_color_for_type ["warnings" ]: True }
1111
+ )
1112
+ nodeid = _get_node_id_with_markup (self ._tw , self .config , rep )
1102
1113
reason = rep .wasxfail
1103
- lines .append (f"{ verbose_word } { pos } { reason } " )
1114
+ lines .append (f"{ markup_word } { nodeid } { reason } " )
1104
1115
1105
1116
def show_skipped (lines : List [str ]) -> None :
1106
1117
skipped : List [CollectReport ] = self .stats .get ("skipped" , [])
1107
1118
fskips = _folded_skips (self .startpath , skipped ) if skipped else []
1108
1119
if not fskips :
1109
1120
return
1110
1121
verbose_word = skipped [0 ]._get_verbose_word (self .config )
1122
+ markup_word = self ._tw .markup (
1123
+ verbose_word , ** {_color_for_type ["warnings" ]: True }
1124
+ )
1125
+ prefix = "Skipped: "
1111
1126
for num , fspath , lineno , reason in fskips :
1112
- if reason .startswith ("Skipped: " ):
1113
- reason = reason [9 :]
1127
+ if reason .startswith (prefix ):
1128
+ reason = reason [len ( prefix ) :]
1114
1129
if lineno is not None :
1115
1130
lines .append (
1116
- "%s [%d] %s:%d: %s"
1117
- % (verbose_word , num , fspath , lineno , reason )
1131
+ "%s [%d] %s:%d: %s" % (markup_word , num , fspath , lineno , reason )
1118
1132
)
1119
1133
else :
1120
- lines .append ("%s [%d] %s: %s" % (verbose_word , num , fspath , reason ))
1134
+ lines .append ("%s [%d] %s: %s" % (markup_word , num , fspath , reason ))
1121
1135
1122
1136
REPORTCHAR_ACTIONS : Mapping [str , Callable [[List [str ]], None ]] = {
1123
1137
"x" : show_xfailed ,
1124
1138
"X" : show_xpassed ,
1125
- "f" : partial (show_simple , "failed" ),
1139
+ "f" : partial (show_simple , stat = "failed" ),
1126
1140
"s" : show_skipped ,
1127
- "p" : partial (show_simple , "passed" ),
1128
- "E" : partial (show_simple , "error" ),
1141
+ "p" : partial (show_simple , stat = "passed" ),
1142
+ "E" : partial (show_simple , stat = "error" ),
1129
1143
}
1130
1144
1131
1145
lines : List [str ] = []
@@ -1135,7 +1149,7 @@ def show_skipped(lines: List[str]) -> None:
1135
1149
action (lines )
1136
1150
1137
1151
if lines :
1138
- self .write_sep ("=" , "short test summary info" )
1152
+ self .write_sep ("=" , "short test summary info" , cyan = True , bold = True )
1139
1153
for line in lines :
1140
1154
self .write_line (line )
1141
1155
@@ -1249,7 +1263,7 @@ def _build_collect_only_summary_stats_line(
1249
1263
return parts , main_color
1250
1264
1251
1265
1252
- def _get_pos ( config : Config , rep : BaseReport ):
1266
+ def _get_node_id_with_markup ( tw : TerminalWriter , config : Config , rep : BaseReport ):
1253
1267
nodeid = config .cwd_relative_nodeid (rep .nodeid )
1254
1268
return nodeid
1255
1269
@@ -1280,13 +1294,14 @@ def _format_trimmed(format: str, msg: str, available_width: int) -> Optional[str
1280
1294
1281
1295
1282
1296
def _get_line_with_reprcrash_message (
1283
- config : Config , rep : BaseReport , termwidth : int
1297
+ config : Config , rep : BaseReport , tw : TerminalWriter , word_markup : Dict [ str , bool ]
1284
1298
) -> str :
1285
1299
"""Get summary line for a report, trying to add reprcrash message."""
1286
1300
verbose_word = rep ._get_verbose_word (config )
1287
- pos = _get_pos (config , rep )
1301
+ word = tw .markup (verbose_word , ** word_markup )
1302
+ node = _get_node_id_with_markup (tw , config , rep )
1288
1303
1289
- line = f"{ verbose_word } { pos } "
1304
+ line = f"{ word } { node } "
1290
1305
line_width = wcswidth (line )
1291
1306
1292
1307
try :
@@ -1295,7 +1310,7 @@ def _get_line_with_reprcrash_message(
1295
1310
except AttributeError :
1296
1311
pass
1297
1312
else :
1298
- available_width = termwidth - line_width
1313
+ available_width = tw . fullwidth - line_width
1299
1314
msg = _format_trimmed (" - {}" , msg , available_width )
1300
1315
if msg is not None :
1301
1316
line += msg
0 commit comments