@@ -1438,8 +1438,10 @@ def _match_lines(self, lines2, match_func, match_nickname):
14381438                    self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (nextline ))
14391439                extralines .append (nextline )
14401440            else :
1441-                 self ._log ("remains unmatched: {!r}" .format (line ))
1442-                 pytest .fail (self ._log_text .lstrip ())
1441+                 msg  =  "remains unmatched: {!r}" .format (line )
1442+                 self ._log (msg )
1443+                 self ._fail (msg )
1444+         self ._log_output  =  []
14431445
14441446    def  no_fnmatch_line (self , pat ):
14451447        """Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``. 
@@ -1465,18 +1467,20 @@ def _no_match_line(self, pat, match_func, match_nickname):
14651467        __tracebackhide__  =  True 
14661468        nomatch_printed  =  False 
14671469        wnick  =  len (match_nickname ) +  1 
1468-         try :
1469-             for  line  in  self .lines :
1470-                 if  match_func (line , pat ):
1471-                     self ._log ("%s:"  %  match_nickname , repr (pat ))
1472-                     self ._log ("{:>{width}}" .format ("with:" , width = wnick ), repr (line ))
1473-                     pytest .fail (self ._log_text .lstrip ())
1474-                 else :
1475-                     if  not  nomatch_printed :
1476-                         self ._log (
1477-                             "{:>{width}}" .format ("nomatch:" , width = wnick ), repr (pat )
1478-                         )
1479-                         nomatch_printed  =  True 
1480-                     self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (line ))
1481-         finally :
1482-             self ._log_output  =  []
1470+         for  line  in  self .lines :
1471+             if  match_func (line , pat ):
1472+                 msg  =  "{}: {!r}" .format (match_nickname , pat )
1473+                 self ._log (msg )
1474+                 self ._log ("{:>{width}}" .format ("with:" , width = wnick ), repr (line ))
1475+                 self ._fail (msg )
1476+             else :
1477+                 if  not  nomatch_printed :
1478+                     self ._log ("{:>{width}}" .format ("nomatch:" , width = wnick ), repr (pat ))
1479+                     nomatch_printed  =  True 
1480+                 self ._log ("{:>{width}}" .format ("and:" , width = wnick ), repr (line ))
1481+         self ._log_output  =  []
1482+ 
1483+     def  _fail (self , msg ):
1484+         log_text  =  self ._log_text 
1485+         self ._log_output  =  []
1486+         pytest .fail (log_text )
0 commit comments