14
14
15
15
from pytest_html import __version__
16
16
from 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
17
20
from pytest_html .util import cleanup_unserializable
18
21
19
-
20
22
try :
21
23
from ansi2html import Ansi2HTMLConverter , style
22
24
31
33
32
34
33
35
class 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
-
65
36
class Report :
66
37
def __init__ (self , title , config ):
67
38
self ._config = config
@@ -100,15 +71,16 @@ def data(self):
100
71
def set_data (self , key , value ):
101
72
self ._data [key ] = value
102
73
103
- def add_test (self , test_data , report ):
74
+ def add_test (self , test_data , report , remove_log = False ):
104
75
# 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 :
106
77
self .update_test_log (report )
107
78
108
79
# passed "setup" and "teardown" are not added to the html
109
80
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 )
112
84
self ._data ["tests" ][report .nodeid ].append (test_data )
113
85
return True
114
86
@@ -117,7 +89,7 @@ def add_test(self, test_data, report):
117
89
def update_test_log (self , report ):
118
90
log = []
119
91
for test in self ._data ["tests" ][report .nodeid ]:
120
- if test ["testId" ] == report .nodeid :
92
+ if test ["testId" ] == report .nodeid and "log" in test :
121
93
for section in report .sections :
122
94
header , content = section
123
95
if "teardown" in header :
@@ -260,7 +232,7 @@ def pytest_sessionstart(self, session):
260
232
261
233
session .config .hook .pytest_html_report_title (report = self ._report )
262
234
263
- header_cells = self . Cells ()
235
+ header_cells = Header ()
264
236
session .config .hook .pytest_html_results_table_header (cells = header_cells )
265
237
266
238
self ._report .set_data ("resultsTableHeader" , header_cells .html )
@@ -301,28 +273,28 @@ def pytest_runtest_logreport(self, report):
301
273
}
302
274
303
275
test_id = report .nodeid
276
+ table_html = Html ()
304
277
if report .when == "call" :
305
- row_cells = self . Cells ()
278
+ row_cells = Row ()
306
279
self ._config .hook .pytest_html_results_table_row (
307
280
report = report , cells = row_cells
308
281
)
309
282
if row_cells .html is None :
310
283
return
311
284
data ["resultsTableRow" ] = row_cells .html
312
285
313
- table_html = []
314
286
self ._config .hook .pytest_html_results_table_html (
315
287
report = report , data = table_html
316
288
)
317
- data ["tableHtml" ] = table_html
289
+ data ["tableHtml" ] = table_html . html [ "html" ]
318
290
else :
319
291
test_id += f"::{ report .when } "
320
292
data ["testId" ] = test_id
321
293
322
294
data ["result" ] = _process_outcome (report )
323
295
data ["extras" ] = self ._process_extras (report , test_id )
324
296
325
- if self ._report .add_test (data , report ):
297
+ if self ._report .add_test (data , report , table_html . replace_log ):
326
298
self ._generate_report ()
327
299
328
300
0 commit comments