@@ -336,37 +336,52 @@ def _append_video(self, extra, extra_index, test_index):
336
336
)
337
337
self .additional_html .append (html .div (html_div , class_ = "video" ))
338
338
339
- class EnvironmentTable :
339
+ class EnvironmentSection :
340
340
def __init__ (self , config ):
341
341
self .metadata = getattr (config , "_metadata" , [])
342
342
self .config = config
343
+ self .environment = []
343
344
self .environment_table = []
344
345
345
- rows = []
346
-
347
- header_cells = [html .th ("Key" ), html .th ("Value" )]
348
- self .config .hook .pytest_html_environment_table_header (cells = header_cells )
349
- rows .append (header_cells )
350
346
if self .metadata :
347
+ self .rows = []
348
+ self ._generate_environment_header ()
349
+
351
350
keys = [k for k in self .metadata .keys ()]
352
351
if not isinstance (self .metadata , OrderedDict ):
353
352
keys .sort ()
354
353
355
354
for key in keys :
356
- value = self .metadata [key ]
357
- if isinstance (value , str ) and value .startswith ("http" ):
358
- value = html .a (value , href = value , target = "_blank" )
359
- elif isinstance (value , (list , tuple , set )):
360
- value = ", " .join (str (i ) for i in sorted (map (str , value )))
361
- elif isinstance (value , dict ):
362
- sorted_dict = {k : value [k ] for k in sorted (value )}
363
- value = json .dumps (sorted_dict )
364
- raw_value_string = raw (str (value ))
365
- row_cells = html .tr (html .td (key ), html .td (raw_value_string ))
366
- self .config .hook .pytest_html_environment_table_row (cells = row_cells )
367
- rows .append (row_cells )
368
-
369
- self .environment_table .append (html .table (rows , id = "environment" ))
355
+ self ._generate_environment_row (key )
356
+
357
+ self ._generate_environment_section ()
358
+
359
+ def _generate_environment_header (self ):
360
+ header_cells = [html .th ("Key" ), html .th ("Value" )]
361
+ self .config .hook .pytest_html_environment_table_header (cells = header_cells )
362
+ self .rows .append (header_cells )
363
+
364
+ def _generate_environment_row (self , key ):
365
+ value = self .metadata [key ]
366
+ if isinstance (value , str ) and value .startswith ("http" ):
367
+ value = html .a (value , href = value , target = "_blank" )
368
+ elif isinstance (value , (list , tuple , set )):
369
+ value = ", " .join (str (i ) for i in sorted (map (str , value )))
370
+ elif isinstance (value , dict ):
371
+ sorted_dict = {k : value [k ] for k in sorted (value )}
372
+ value = json .dumps (sorted_dict )
373
+ raw_value_string = raw (str (value ))
374
+ row_cells = html .tr (html .td (key ), html .td (raw_value_string ))
375
+ self .config .hook .pytest_html_environment_table_row (cells = row_cells )
376
+ self .rows .append (row_cells )
377
+
378
+ def _generate_environment_table (self ):
379
+ self .environment_table .append (html .table (self .rows , id = "environment" ))
380
+
381
+ def _generate_environment_section (self ):
382
+ if self .environment_table :
383
+ self .environment = [html .h2 ("Environment" )]
384
+ self .environment .append (self .environment_table )
370
385
371
386
def _appendrow (self , outcome , report ):
372
387
result = self .TestResult (outcome , report , self .logfile , self .config )
@@ -564,7 +579,7 @@ def generate_summary_item(self):
564
579
onLoad = "init()" ,
565
580
)
566
581
567
- body .extend (self ._generate_environment (session .config ))
582
+ body .extend (self .EnvironmentSection (session .config ). environment_table )
568
583
569
584
summary_prefix , summary_postfix = [], []
570
585
session .config .hook .pytest_html_results_summary (
@@ -582,15 +597,6 @@ def generate_summary_item(self):
582
597
unicode_doc = unicode_doc .encode ("utf-8" , errors = "xmlcharrefreplace" )
583
598
return unicode_doc .decode ("utf-8" )
584
599
585
- def _generate_environment (self , config ):
586
- environment_table = self .EnvironmentTable (config ).environment_table
587
- if environment_table :
588
- environment = [html .h2 ("Environment" )]
589
- environment .append (environment_table )
590
- else :
591
- environment = []
592
- return environment
593
-
594
600
def _save_report (self , report_content ):
595
601
dir_name = os .path .dirname (self .logfile )
596
602
assets_dir = os .path .join (dir_name , "assets" )
0 commit comments