@@ -1049,6 +1049,7 @@ class LineMatcher:
1049
1049
1050
1050
def __init__ (self , lines ):
1051
1051
self .lines = lines
1052
+ self ._log_output = []
1052
1053
1053
1054
def str (self ):
1054
1055
"""Return the entire original text."""
@@ -1072,10 +1073,11 @@ def fnmatch_lines_random(self, lines2):
1072
1073
for line in lines2 :
1073
1074
for x in self .lines :
1074
1075
if line == x or fnmatch (x , line ):
1075
- print_ ("matched: " , repr (line ))
1076
+ self . _log ("matched: " , repr (line ))
1076
1077
break
1077
1078
else :
1078
- raise ValueError ("line %r not found in output" % line )
1079
+ self ._log ("line %r not found in output" % line )
1080
+ raise ValueError (self ._log_text )
1079
1081
1080
1082
def get_lines_after (self , fnline ):
1081
1083
"""Return all lines following the given line in the text.
@@ -1087,6 +1089,13 @@ def get_lines_after(self, fnline):
1087
1089
return self .lines [i + 1 :]
1088
1090
raise ValueError ("line %r not found in output" % fnline )
1089
1091
1092
+ def _log (self , * args ):
1093
+ self ._log_output .append (' ' .join ((str (x ) for x in args )))
1094
+
1095
+ @property
1096
+ def _log_text (self ):
1097
+ return '\n ' .join (self ._log_output )
1098
+
1090
1099
def fnmatch_lines (self , lines2 ):
1091
1100
"""Search the text for matching lines.
1092
1101
@@ -1096,8 +1105,6 @@ def fnmatch_lines(self, lines2):
1096
1105
stdout.
1097
1106
1098
1107
"""
1099
- def show (arg1 , arg2 ):
1100
- py .builtin .print_ (arg1 , arg2 , file = sys .stderr )
1101
1108
lines2 = self ._getlines (lines2 )
1102
1109
lines1 = self .lines [:]
1103
1110
nextline = None
@@ -1108,17 +1115,18 @@ def show(arg1, arg2):
1108
1115
while lines1 :
1109
1116
nextline = lines1 .pop (0 )
1110
1117
if line == nextline :
1111
- show ("exact match:" , repr (line ))
1118
+ self . _log ("exact match:" , repr (line ))
1112
1119
break
1113
1120
elif fnmatch (nextline , line ):
1114
- show ("fnmatch:" , repr (line ))
1115
- show (" with:" , repr (nextline ))
1121
+ self . _log ("fnmatch:" , repr (line ))
1122
+ self . _log (" with:" , repr (nextline ))
1116
1123
break
1117
1124
else :
1118
1125
if not nomatchprinted :
1119
- show ("nomatch:" , repr (line ))
1126
+ self . _log ("nomatch:" , repr (line ))
1120
1127
nomatchprinted = True
1121
- show (" and:" , repr (nextline ))
1128
+ self . _log (" and:" , repr (nextline ))
1122
1129
extralines .append (nextline )
1123
1130
else :
1124
- pytest .fail ("remains unmatched: %r, see stderr" % (line ,))
1131
+ self ._log ("remains unmatched: %r" % (line ,))
1132
+ pytest .fail (self ._log_text )
0 commit comments