@@ -173,7 +173,12 @@ def __init__(self, outcome, report, logfile, config):
173173 for extra_index , extra in enumerate (getattr (report , "extra" , [])):
174174 self .append_extra_html (extra , extra_index , test_index )
175175
176- self .append_log_html (report , self .additional_html , config .option .capture )
176+ self .append_log_html (
177+ report ,
178+ self .additional_html ,
179+ config .option .capture ,
180+ config .option .showcapture ,
181+ )
177182
178183 cells = [
179184 html .td (self .outcome , class_ = "col-result" ),
@@ -277,47 +282,60 @@ def append_extra_html(self, extra, extra_index, test_index):
277282 )
278283 self .links_html .append (" " )
279284
280- def append_log_html (self , report , additional_html , pytest_capture_value ):
281- log = html .div (class_ = "log" )
282-
283- if pytest_capture_value != "no" :
284- if report .longrepr :
285- # longreprtext is only filled out on failure by pytest
286- # otherwise will be None.
287- # Use full_text if longreprtext is None-ish
288- # we added full_text elsewhere in this file.
289- text = report .longreprtext or report .full_text
290- for line in text .splitlines ():
291- separator = line .startswith ("_ " * 10 )
292- if separator :
293- log .append (line [:80 ])
285+ def _populate_html_log_div (self , log , report ):
286+ if report .longrepr :
287+ # longreprtext is only filled out on failure by pytest
288+ # otherwise will be None.
289+ # Use full_text if longreprtext is None-ish
290+ # we added full_text elsewhere in this file.
291+ text = report .longreprtext or report .full_text
292+ for line in text .splitlines ():
293+ separator = line .startswith ("_ " * 10 )
294+ if separator :
295+ log .append (line [:80 ])
296+ else :
297+ exception = line .startswith ("E " )
298+ if exception :
299+ log .append (html .span (raw (escape (line )), class_ = "error" ))
294300 else :
295- exception = line .startswith ("E " )
296- if exception :
297- log .append (html .span (raw (escape (line )), class_ = "error" ))
298- else :
299- log .append (raw (escape (line )))
300- log .append (html .br ())
301-
302- for section in report .sections :
303- header , content = map (escape , section )
304- log .append (f" { header :-^80} " )
301+ log .append (raw (escape (line )))
305302 log .append (html .br ())
306303
307- if ansi_support ():
308- converter = ansi_support ().Ansi2HTMLConverter (
309- inline = False , escaped = False
310- )
311- content = converter .convert (content , full = False )
312- else :
313- content = _remove_ansi_escape_sequences (content )
304+ for section in report .sections :
305+ header , content = map (escape , section )
306+ log .append (f" { header :-^80} " )
307+ log .append (html .br ())
314308
315- log .append (raw (content ))
316- log .append (html .br ())
309+ if ansi_support ():
310+ converter = ansi_support ().Ansi2HTMLConverter (
311+ inline = False , escaped = False
312+ )
313+ content = converter .convert (content , full = False )
314+ else :
315+ content = _remove_ansi_escape_sequences (content )
316+
317+ log .append (raw (content ))
318+ log .append (html .br ())
319+
320+ def append_log_html (
321+ self ,
322+ report ,
323+ additional_html ,
324+ pytest_capture_value ,
325+ pytest_show_capture_value ,
326+ ):
327+ log = html .div (class_ = "log" )
328+
329+ should_skip_captured_output = pytest_capture_value == "no"
330+ if report .outcome == "failed" and not should_skip_captured_output :
331+ should_skip_captured_output = pytest_show_capture_value == "no"
332+ if not should_skip_captured_output :
333+ self ._populate_html_log_div (log , report )
317334
318335 if len (log ) == 0 :
319336 log = html .div (class_ = "empty log" )
320337 log .append ("No log output captured." )
338+
321339 additional_html .append (log )
322340
323341 def _make_media_html_div (
0 commit comments