diff --git a/docs/changelog.rst b/docs/changelog.rst index e1f52a22..bf9f700d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,23 @@ Changelog Versions follow `Semantic Versioning`_ (``..``). +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 --------------- diff --git a/src/pytest_html/hooks.py b/src/pytest_html/hooks.py index 7b75120b..1937f760 100644 --- a/src/pytest_html/hooks.py +++ b/src/pytest_html/hooks.py @@ -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. """ diff --git a/src/pytest_html/html_report.py b/src/pytest_html/html_report.py index 66e10f07..4528a730 100644 --- a/src/pytest_html/html_report.py +++ b/src/pytest_html/html_report.py @@ -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 @@ -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")