Skip to content

Commit 4ccf77e

Browse files
Merge pull request #201 from prashanth-sams/200
#200
2 parents 1225c22 + c91fae7 commit 4ccf77e

File tree

8 files changed

+160
-44
lines changed

8 files changed

+160
-44
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Library
22
/pytest_html_reporter/ @prashanth-sams
3-
/tests/ @prashanth-sams
4-
/unittests/ @prashanth-sams
3+
/tests/ @prashanth-sams

CHANGELOG.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
Change Log
22
==========
33

4+
0.2.8 (11/02/2022)
5+
-------------------
6+
- Fixed all the code related inconsistencies
7+
8+
0.2.7 (11/02/2022)
9+
-------------------
10+
- Added custom title on Dashboard
11+
12+
0.2.6 (25/04/2021)
13+
-------------------
14+
- Dashboard Execution Time in H:M:S Hour:Minute:Second format
15+
- Shortened long error text to open in a dialog box
16+
17+
0.2.5 (20/04/2021)
18+
-------------------
19+
- Fixed incorrect execution time in the test metrics
20+
21+
0.2.4 (19/04/2021)
22+
-------------------
23+
- Added support to download the current report (dashboard) in pdf format
24+
25+
0.2.3 (28/09/2020)
26+
-------------------
27+
- Fixed UI bugs in dashboard and Archives layout
28+
- Added error details on failed test cases
29+
430
0.2.2 (13/09/2020)
531
-------------------
632
- Codecov

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Installation
4747

4848
.. code-block:: console
4949
50-
$ pip install pytest-html-reporter
50+
$ pip3 install pytest-html-reporter
5151
5252
5353
Usage

pytest_html_reporter/plugin.py

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import json
99
import glob
1010
from collections import Counter
11-
import codecs
1211
from PIL import Image
1312
from io import BytesIO
1413
import 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

Comments
 (0)