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
@@ -100,15 +71,16 @@ def data(self):
10071 def set_data (self , key , value ):
10172 self ._data [key ] = value
10273
103- def add_test (self , test_data , report ):
74+ def add_test (self , test_data , report , remove_log = False ):
10475 # regardless of pass or fail we must add teardown logging to "call"
105- if report .when == "teardown" :
76+ if report .when == "teardown" and not remove_log :
10677 self .update_test_log (report )
10778
10879 # passed "setup" and "teardown" are not added to the html
10980 if report .when == "call" or _is_error (report ):
110- processed_logs = _process_logs (report )
111- test_data ["log" ] = _handle_ansi (processed_logs )
81+ if not remove_log :
82+ processed_logs = _process_logs (report )
83+ test_data ["log" ] = _handle_ansi (processed_logs )
11284 self ._data ["tests" ][report .nodeid ].append (test_data )
11385 return True
11486
@@ -117,7 +89,7 @@ def add_test(self, test_data, report):
11789 def update_test_log (self , report ):
11890 log = []
11991 for test in self ._data ["tests" ][report .nodeid ]:
120- if test ["testId" ] == report .nodeid :
92+ if test ["testId" ] == report .nodeid and "log" in test :
12193 for section in report .sections :
12294 header , content = section
12395 if "teardown" in header :
@@ -260,7 +232,7 @@ def pytest_sessionstart(self, session):
260232
261233 session .config .hook .pytest_html_report_title (report = self ._report )
262234
263- header_cells = self . Cells ()
235+ header_cells = Header ()
264236 session .config .hook .pytest_html_results_table_header (cells = header_cells )
265237
266238 self ._report .set_data ("resultsTableHeader" , header_cells .html )
@@ -301,28 +273,28 @@ def pytest_runtest_logreport(self, report):
301273 }
302274
303275 test_id = report .nodeid
276+ table_html = Html ()
304277 if report .when == "call" :
305- row_cells = self . Cells ()
278+ row_cells = Row ()
306279 self ._config .hook .pytest_html_results_table_row (
307280 report = report , cells = row_cells
308281 )
309282 if row_cells .html is None :
310283 return
311284 data ["resultsTableRow" ] = row_cells .html
312285
313- table_html = []
314286 self ._config .hook .pytest_html_results_table_html (
315287 report = report , data = table_html
316288 )
317- data ["tableHtml" ] = table_html
289+ data ["tableHtml" ] = table_html . html [ "html" ]
318290 else :
319291 test_id += f"::{ report .when } "
320292 data ["testId" ] = test_id
321293
322294 data ["result" ] = _process_outcome (report )
323295 data ["extras" ] = self ._process_extras (report , test_id )
324296
325- if self ._report .add_test (data , report ):
297+ if self ._report .add_test (data , report , table_html . replace_log ):
326298 self ._generate_report ()
327299
328300
0 commit comments