@@ -149,6 +149,15 @@ def _run_count(self):
149
149
150
150
return f"{ counts } /{ self ._report .collected_items } { 'tests' if plural else 'test' } done."
151
151
152
+ def _hydrate_data (self , data , cells ):
153
+ for index , cell in enumerate (cells ):
154
+ # extract column name and data if column is sortable
155
+ if "sortable" in self ._report .table_header [index ]:
156
+ name_match = re .search (r"col-(\w+)" , cell )
157
+ data_match = re .search (r"<td.*?>(.*?)</td>" , cell )
158
+ if name_match and data_match :
159
+ data [name_match .group (1 )] = data_match .group (1 )
160
+
152
161
@pytest .hookimpl (trylast = True )
153
162
def pytest_sessionstart (self , session ):
154
163
self ._report .set_data ("environment" , self ._generate_environment ())
@@ -193,35 +202,33 @@ def pytest_runtest_logreport(self, report):
193
202
)
194
203
195
204
outcome = _process_outcome (report )
196
- data = {
197
- "result" : outcome ,
198
- "duration" : _format_duration (report .duration ),
199
- }
205
+ duration = _format_duration (report .duration )
200
206
self ._report .total_duration += report .duration
201
207
202
208
test_id = report .nodeid
203
209
if report .when != "call" :
204
210
test_id += f"::{ report .when } "
205
- data ["testId" ] = test_id
206
211
207
- data ["extras" ] = self ._process_extras (report , test_id )
212
+ data = {
213
+ "extras" : self ._process_extras (report , test_id ),
214
+ }
208
215
links = [
209
216
extra
210
217
for extra in data ["extras" ]
211
218
if extra ["format_type" ] in ["json" , "text" , "url" ]
212
219
]
213
220
cells = [
214
- f'<td class="col-result">{ data [ "result" ] } </td>' ,
215
- f'<td class="col-name ">{ data [ "testId" ] } </td>' ,
216
- f'<td class="col-duration">{ data [ " duration" ] } </td>' ,
221
+ f'<td class="col-result">{ outcome } </td>' ,
222
+ f'<td class="col-testId ">{ test_id } </td>' ,
223
+ f'<td class="col-duration">{ duration } </td>' ,
217
224
f'<td class="col-links">{ _process_links (links )} </td>' ,
218
225
]
219
-
220
226
self ._config .hook .pytest_html_results_table_row (report = report , cells = cells )
221
227
if not cells :
222
228
return
223
229
224
230
cells = _fix_py (cells )
231
+ self ._hydrate_data (data , cells )
225
232
data ["resultsTableRow" ] = cells
226
233
227
234
# don't count passed setups and teardowns
0 commit comments