Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ Changelog

Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).

Version History
---------------
3.2.1(2021-02-15)

* Implement functionalitly to add/customize logo on Tests reports page.

* Report Logo

* By default the report logo will be None.

* you can edit it by using the pytest_html_report_logo hook

Usage:

def pytest_html_report_logo(report):
report.img_path = 'Path to Logo Image.'

Version History
---------------

Expand Down
4 changes: 4 additions & 0 deletions src/pytest_html/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ def pytest_html_results_table_row(report, cells):

def pytest_html_results_table_html(report, data):
""" Called after building results table additional HTML. """


def pytest_html_report_logo(report):
""" Called before adding the image to the report. """
6 changes: 6 additions & 0 deletions src/pytest_html/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, logfile, config):
self.logfile = os.path.abspath(logfile)
self.test_logs = []
self.title = os.path.basename(self.logfile)
self.img_path = None
self.results = []
self.errors = self.failed = 0
self.passed = self.skipped = 0
Expand Down Expand Up @@ -182,9 +183,14 @@ def _generate_report(self, session):
) as main_js_fp:
main_js = main_js_fp.read()

def image_visiblity_on_error():
if self.img_path is None:
return "this.style.display='none'"

body = html.body(
html.script(raw(main_js)),
html.h1(self.title),
html.img(src=self.img_path, onerror=image_visiblity_on_error()),
html.p(
"Report generated on {} at {} by ".format(
generated.strftime("%d-%b-%Y"), generated.strftime("%H:%M:%S")
Expand Down