88import json
99import glob
1010from collections import Counter
11- import codecs
1211from PIL import Image
1312from io import BytesIO
1413import shutil
@@ -203,9 +202,12 @@ def __init__(self, path, config):
203202 self .rerun = 0 if has_rerun else None
204203
205204 def pytest_runtest_teardown (self , item , nextitem ):
206- global _test_name
205+ global _test_name , _duration
207206 _test_name = item .name
208207
208+ _test_end_time = time .time ()
209+ _duration = _test_end_time - _start_execution_time
210+
209211 if (self .rerun is not None ) and (max_rerun () is not None ): self .previous_test_name (_test_name )
210212 self ._test_names (_test_name )
211213 self .append_test_metrics_row ()
@@ -222,7 +224,7 @@ def previous_test_name(self, _test_name):
222224
223225 def pytest_runtest_setup (item ):
224226 global _start_execution_time
225- _start_execution_time = round ( time .time () )
227+ _start_execution_time = time .time ()
226228
227229 def pytest_sessionfinish (self , session ):
228230 if _suite_name is not None : self .append_suite_metrics_row (_suite_name )
@@ -259,6 +261,11 @@ def pytest_terminal_summary(self, terminalreporter, exitstatus, config):
259261 global _execution_time
260262 _execution_time = time .time () - terminalreporter ._sessionstarttime
261263
264+ if _execution_time < 60 :
265+ _execution_time = str (round (_execution_time , 2 )) + " secs"
266+ else :
267+ _execution_time = str (time .strftime ("%H:%M:%S" , time .gmtime (round (_execution_time )))) + " Hrs"
268+
262269 global _total
263270 _total = _pass + _fail + _xpass + _xfail + _skip + _error
264271
@@ -330,9 +337,8 @@ def pytest_runtest_makereport(self, item, call):
330337 for line in rep .longreprtext .splitlines ():
331338 exception = line .startswith ("E " )
332339 if exception :
333- # self.update_test_error(line.replace("E ", ""))
334340 longerr += line + "\n "
335- self .update_test_error (longerr )
341+ self .update_test_error (longerr . replace ( "E " , "" ) )
336342 else :
337343 self .increment_error ()
338344 self .update_test_status ("ERROR" )
@@ -347,29 +353,56 @@ def pytest_runtest_makereport(self, item, call):
347353 self .increment_xfail ()
348354 self .update_test_status ("xFAIL" )
349355 if rep .longrepr :
356+ longerr = ""
350357 for line in rep .longreprtext .splitlines ():
351358 exception = line .startswith ("E " )
352359 if exception :
353- self .update_test_error (line .replace ("E " , "" ))
360+ longerr += line + "\n "
361+ self .update_test_error (longerr .replace ("E " , "" ))
354362 else :
355363 self .increment_skip ()
356364 self .update_test_status ("SKIP" )
357365 if rep .longrepr :
366+ longerr = ""
358367 for line in rep .longreprtext .splitlines ():
359- self .update_test_error (line )
368+ longerr += line + "\n "
369+ self .update_test_error (longerr )
360370
361371 def append_test_metrics_row (self ):
362- global _test_metrics_content , _pvalue
372+ global _test_metrics_content , _pvalue , _duration
363373
364374 test_row_text = """
365375 <tr>
366376 <td style="word-wrap: break-word;max-width: 200px; white-space: normal; text-align:left">__sname__</td>
367377 <td style="word-wrap: break-word;max-width: 200px; white-space: normal; text-align:left">__name__</td>
368378 <td>__stat__</td>
369379 <td>__dur__</td>
370- <td style="word-wrap: break-word;max-width: 200px; white-space: normal; text-align:left"">__msg__</td>
380+ <td style="word-wrap: break-word;max-width: 200px; white-space: normal; text-align:left"">
381+ __msg__
382+ __floating_error_text__
383+ </td>
371384 </tr>
372385 """
386+
387+ floating_error_text = """
388+ <a data-toggle="modal" href="#myModal-__runt__" class="">(...)</a>
389+ <div class="modal fade in" id="myModal-__runt__" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
390+ <div class="modal-dialog">
391+ <div class="modal-content">
392+ <div class="modal-body">
393+ <p>
394+ <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" width="1.12em" height="1em" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);" preserveAspectRatio="xMidYMid meet" viewBox="0 0 1856 1664"><path d="M1056 1375v-190q0-14-9.5-23.5t-22.5-9.5H832q-13 0-22.5 9.5T800 1185v190q0 14 9.5 23.5t22.5 9.5h192q13 0 22.5-9.5t9.5-23.5zm-2-374l18-459q0-12-10-19q-13-11-24-11H818q-11 0-24 11q-10 7-10 21l17 457q0 10 10 16.5t24 6.5h185q14 0 23.5-6.5t10.5-16.5zm-14-934l768 1408q35 63-2 126q-17 29-46.5 46t-63.5 17H160q-34 0-63.5-17T50 1601q-37-63-2-126L816 67q17-31 47-49t65-18t65 18t47 49z" fill="#DC143C"/></svg>
395+ __full_msg__
396+ </p>
397+ </div>
398+ <div class="modal-footer">
399+ <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
400+ </div>
401+ </div>
402+ </div>
403+ </div>
404+ """
405+
373406 if (self .rerun is not None ) and (max_rerun () is not None ):
374407 if (_test_status == 'FAIL' ) or (_test_status == 'ERROR' ): _pvalue += 1
375408
@@ -381,7 +414,15 @@ def append_test_metrics_row(self):
381414 test_row_text = test_row_text .replace ("__name__" , str (_test_name ))
382415 test_row_text = test_row_text .replace ("__stat__" , str (_test_status ))
383416 test_row_text = test_row_text .replace ("__dur__" , str (round (_duration , 2 )))
384- test_row_text = test_row_text .replace ("__msg__" , str (_current_error ))
417+ test_row_text = test_row_text .replace ("__msg__" , str (_current_error [:50 ]))
418+ floating_error_text = floating_error_text .replace ("__runt__" , str (time .time ()).replace ('.' , '' ))
419+
420+ if len (_current_error ) < 49 :
421+ test_row_text = test_row_text .replace ("__floating_error_text__" , str ('' ))
422+ else :
423+ test_row_text = test_row_text .replace ("__floating_error_text__" , str (floating_error_text ))
424+ test_row_text = test_row_text .replace ("__full_msg__" , str (_current_error ))
425+
385426
386427 _test_metrics_content += test_row_text
387428 _pvalue = 0
@@ -391,7 +432,14 @@ def append_test_metrics_row(self):
391432 test_row_text = test_row_text .replace ("__name__" , str (_test_name ))
392433 test_row_text = test_row_text .replace ("__stat__" , str (_test_status ))
393434 test_row_text = test_row_text .replace ("__dur__" , str (round (_duration , 2 )))
394- test_row_text = test_row_text .replace ("__msg__" , str (_current_error ))
435+ test_row_text = test_row_text .replace ("__msg__" , str (_current_error [:50 ]))
436+ floating_error_text = floating_error_text .replace ("__runt__" , str (time .time ()).replace ('.' , '' ))
437+
438+ if len (_current_error ) < 49 :
439+ test_row_text = test_row_text .replace ("__floating_error_text__" , str ('' ))
440+ else :
441+ test_row_text = test_row_text .replace ("__floating_error_text__" , str (floating_error_text ))
442+ test_row_text = test_row_text .replace ("__full_msg__" , str (_current_error ))
395443
396444 _test_metrics_content += test_row_text
397445
@@ -403,7 +451,14 @@ def append_test_metrics_row(self):
403451 test_row_text = test_row_text .replace ("__name__" , str (_test_name ))
404452 test_row_text = test_row_text .replace ("__stat__" , str (_test_status ))
405453 test_row_text = test_row_text .replace ("__dur__" , str (round (_duration , 2 )))
406- test_row_text = test_row_text .replace ("__msg__" , str (_current_error ))
454+ test_row_text = test_row_text .replace ("__msg__" , str (_current_error [:50 ]))
455+ floating_error_text = floating_error_text .replace ("__runt__" , str (time .time ()).replace ('.' , '' ))
456+
457+ if len (_current_error ) < 49 :
458+ test_row_text = test_row_text .replace ("__floating_error_text__" , str ('' ))
459+ else :
460+ test_row_text = test_row_text .replace ("__floating_error_text__" , str (floating_error_text ))
461+ test_row_text = test_row_text .replace ("__full_msg__" , str (_current_error ))
407462
408463 _test_metrics_content += test_row_text
409464
@@ -632,7 +687,7 @@ def _test_error(self, value):
632687 def renew_template_text (self , logo_url ):
633688 template_text = html_template ()
634689 template_text = template_text .replace ("__custom_logo__" , logo_url )
635- template_text = template_text .replace ("__execution_time__" , str (round ( _execution_time , 2 ) ))
690+ template_text = template_text .replace ("__execution_time__" , str (_execution_time ))
636691 template_text = template_text .replace ("__title__" , _title )
637692 # template_text = template_text.replace("__executed_by__", str(platform.uname()[1]))
638693 # template_text = template_text.replace("__os_name__", str(platform.uname()[0]))
0 commit comments