Skip to content

Commit 6553da9

Browse files
enhance html output structure to allow for easier styling
content will be created with the following document structure: body .content .content-header h1 .content-environment .content-summary .content-results #results-container Javascript for dealing with table interactivity has been updated to use container id instead of relying on appending as final element of body.
1 parent b5a02fb commit 6553da9

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

pytest_html/plugin.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,29 +524,34 @@ def generate_summary_item(self):
524524

525525
session.config.hook.pytest_html_report_title(report=self)
526526

527+
content = [html.h1(self.title),
528+
html.p("Report generated on {} at {} by "\
529+
.format(generated.strftime("%d-%b-%Y"),
530+
generated.strftime("%H:%M:%S")),
531+
html.a("pytest-html", href=__pypi_url__),f" v{__version__}",)]
532+
533+
summary_prefix, summary_postfix = [], []
534+
session.config.hook.pytest_html_results_summary(prefix=summary_prefix,
535+
summary=summary,
536+
postfix=summary_postfix)
537+
summary = [html.h2("Summary"), *summary_prefix, *summary, *summary_postfix]
538+
527539
body = html.body(
528540
html.script(raw(main_js)),
529-
html.h1(self.title),
530-
html.p(
531-
"Report generated on {} at {} by ".format(
532-
generated.strftime("%d-%b-%Y"), generated.strftime("%H:%M:%S")
533-
),
534-
html.a("pytest-html", href=__pypi_url__),
535-
f" v{__version__}",
536-
),
541+
html.div(html.div(
542+
html.h1(self.title),
543+
html.p("Report generated on {} at {} by "\
544+
.format(generated.strftime("%d-%b-%Y"),
545+
generated.strftime("%H:%M:%S")),
546+
html.a("pytest-html", href=__pypi_url__),f" v{__version__}",),
547+
html.div(*self._generate_environment(session.config), class_="content-environment"),
548+
html.div(*summary, class_="content-summary"),
549+
class_="content-header"),
550+
html.div(*results, class_="content-results", id="results-container"),
551+
class_="content"),
537552
onLoad="init()",
538553
)
539554

540-
body.extend(self._generate_environment(session.config))
541-
542-
summary_prefix, summary_postfix = [], []
543-
session.config.hook.pytest_html_results_summary(
544-
prefix=summary_prefix, summary=summary, postfix=summary_postfix
545-
)
546-
body.extend([html.h2("Summary")] + summary_prefix + summary + summary_postfix)
547-
548-
body.extend(results)
549-
550555
doc = html.html(head, body)
551556

552557
unicode_doc = "<!DOCTYPE html>\n{}".format(doc.unicode(indent=2))

pytest_html/resources/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function sort_table(clicked, key_func) {
139139
sorted_rows.forEach(function(elem) {
140140
parent.appendChild(elem);
141141
});
142-
document.getElementsByTagName("BODY")[0].appendChild(parent);
142+
document.getElementById("results-container").appendChild(parent);
143143
}
144144

145145
function sort(items, key_func, reversed) {

0 commit comments

Comments
 (0)