@@ -1421,10 +1421,10 @@ def _match_lines(self, lines2, match_func, match_nickname):
1421
1421
self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (nextline ))
1422
1422
extralines .append (nextline )
1423
1423
else :
1424
- self . _log ( "remains unmatched: {!r}" .format (line ) )
1425
- pytest . fail (
1426
- self ._log_text , short_msg = "remains unmatched: {!r}" . format ( line )
1427
- )
1424
+ msg = "remains unmatched: {!r}" .format (line )
1425
+ self . _log ( msg )
1426
+ self ._fail ( msg )
1427
+ self . _log_output = []
1428
1428
1429
1429
def no_fnmatch_line (self , pat ):
1430
1430
"""Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``.
@@ -1450,18 +1450,20 @@ def _no_match_line(self, pat, match_func, match_nickname):
1450
1450
__tracebackhide__ = True
1451
1451
nomatch_printed = False
1452
1452
wnick = len (match_nickname ) + 1
1453
- try :
1454
- for line in self .lines :
1455
- if match_func (line , pat ):
1456
- self ._log ("%s:" % match_nickname , repr (pat ))
1457
- self ._log ("{:>{width}}" .format ("with:" , width = wnick ), repr (line ))
1458
- pytest .fail (self ._log_text .lstrip ())
1459
- else :
1460
- if not nomatch_printed :
1461
- self ._log (
1462
- "{:>{width}}" .format ("nomatch:" , width = wnick ), repr (pat )
1463
- )
1464
- nomatch_printed = True
1465
- self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (line ))
1466
- finally :
1467
- self ._log_output = []
1453
+ for line in self .lines :
1454
+ if match_func (line , pat ):
1455
+ msg = "{}: {!r}" .format (match_nickname , pat )
1456
+ self ._log (msg )
1457
+ self ._log ("{:>{width}}" .format ("with:" , width = wnick ), repr (line ))
1458
+ self ._fail (msg )
1459
+ else :
1460
+ if not nomatch_printed :
1461
+ self ._log ("{:>{width}}" .format ("nomatch:" , width = wnick ), repr (pat ))
1462
+ nomatch_printed = True
1463
+ self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (line ))
1464
+ self ._log_output = []
1465
+
1466
+ def _fail (self , msg ):
1467
+ log_text = self ._log_text
1468
+ self ._log_output = []
1469
+ pytest .fail (log_text , short_msg = msg )
0 commit comments