1414
1515from pytest_html import __version__
1616from pytest_html import extras
17+ from pytest_html .table import Header
18+ from pytest_html .table import Html
19+ from pytest_html .table import Row
1720from pytest_html .util import cleanup_unserializable
1821
19-
2022try :
2123 from ansi2html import Ansi2HTMLConverter , style
2224
3133
3234
3335class BaseReport :
34- class Cells :
35- def __init__ (self ):
36- self ._html = {}
37-
38- def __delitem__ (self , key ):
39- # This means the item should be removed
40- self ._html = None
41-
42- @property
43- def html (self ):
44- return self ._html
45-
46- def insert (self , index , html ):
47- # backwards-compat
48- if not isinstance (html , str ):
49- if html .__module__ .startswith ("py." ):
50- warnings .warn (
51- "The 'py' module is deprecated and support "
52- "will be removed in a future release." ,
53- DeprecationWarning ,
54- )
55- html = str (html )
56- html = html .replace ("col" , "data-column-type" )
57- self ._html [index ] = html
58-
59- def pop (self , * args ):
60- warnings .warn (
61- "'pop' is deprecated and no longer supported." ,
62- DeprecationWarning ,
63- )
64-
6536 class Report :
6637 def __init__ (self , title , config ):
6738 self ._config = config
@@ -98,15 +69,16 @@ def data(self):
9869 def set_data (self , key , value ):
9970 self ._data [key ] = value
10071
101- def add_test (self , test_data , report ):
72+ def add_test (self , test_data , report , remove_log = False ):
10273 # regardless of pass or fail we must add teardown logging to "call"
103- if report .when == "teardown" :
74+ if report .when == "teardown" and not remove_log :
10475 self .update_test_log (report )
10576
10677 # passed "setup" and "teardown" are not added to the html
10778 if report .when == "call" or _is_error (report ):
108- processed_logs = _process_logs (report )
109- test_data ["log" ] = _handle_ansi (processed_logs )
79+ if not remove_log :
80+ processed_logs = _process_logs (report )
81+ test_data ["log" ] = _handle_ansi (processed_logs )
11082 self ._data ["tests" ][report .nodeid ].append (test_data )
11183 return True
11284
@@ -115,7 +87,7 @@ def add_test(self, test_data, report):
11587 def update_test_log (self , report ):
11688 log = []
11789 for test in self ._data ["tests" ][report .nodeid ]:
118- if test ["testId" ] == report .nodeid :
90+ if test ["testId" ] == report .nodeid and "log" in test :
11991 for section in report .sections :
12092 header , content = section
12193 if "teardown" in header :
@@ -258,7 +230,7 @@ def pytest_sessionstart(self, session):
258230
259231 session .config .hook .pytest_html_report_title (report = self ._report )
260232
261- header_cells = self . Cells ()
233+ header_cells = Header ()
262234 session .config .hook .pytest_html_results_table_header (cells = header_cells )
263235
264236 self ._report .set_data ("resultsTableHeader" , header_cells .html )
@@ -299,28 +271,28 @@ def pytest_runtest_logreport(self, report):
299271 }
300272
301273 test_id = report .nodeid
274+ table_html = Html ()
302275 if report .when == "call" :
303- row_cells = self . Cells ()
276+ row_cells = Row ()
304277 self ._config .hook .pytest_html_results_table_row (
305278 report = report , cells = row_cells
306279 )
307280 if row_cells .html is None :
308281 return
309282 data ["resultsTableRow" ] = row_cells .html
310283
311- table_html = []
312284 self ._config .hook .pytest_html_results_table_html (
313285 report = report , data = table_html
314286 )
315- data ["tableHtml" ] = table_html
287+ data ["tableHtml" ] = table_html . html [ "html" ]
316288 else :
317289 test_id += f"::{ report .when } "
318290 data ["testId" ] = test_id
319291
320292 data ["result" ] = _process_outcome (report )
321293 data ["extras" ] = self ._process_extras (report , test_id )
322294
323- if self ._report .add_test (data , report ):
295+ if self ._report .add_test (data , report , table_html . replace_log ):
324296 self ._generate_report ()
325297
326298
0 commit comments