Skip to content

Commit

Permalink
I dunno
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil committed Jul 17, 2023
1 parent 316246e commit 8302d2e
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ classifiers = [
]
dependencies = [
"pytest>=7.0.0",
"pytest-metadata>=2.0.2",
"pytest-metadata>=3.0.0",
"Jinja2>=3.0.0",
]
dynamic = [
Expand Down
76 changes: 51 additions & 25 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

from pytest_html import __version__
from pytest_html import extras
from pytest_html.table import Header
from pytest_html.table import Row
from pytest_html.util import cleanup_unserializable

# from pytest_html.table import Row


class BaseReport:
def __init__(self, report_path, config, report_data, template, css):
Expand Down Expand Up @@ -60,8 +60,8 @@ def _generate_report(self, self_contained=False):

self._write_report(rendered_report)

def _generate_environment(self):
metadata = self._config._metadata
def _generate_environment(self, metadata_key):
metadata = self._config.stash[metadata_key] # self._config._metadata
for key in metadata.keys():
value = metadata[key]
if self._is_redactable_environment_variable(key):
Expand Down Expand Up @@ -145,16 +145,20 @@ def _write_report(self, rendered_report):

@pytest.hookimpl(trylast=True)
def pytest_sessionstart(self, session):
config = session.config
if hasattr(config, "_metadata") and config._metadata:
self._report.set_data("environment", self._generate_environment())
# config = session.config
from pytest_metadata.plugin import metadata_key

# if hasattr(config, "_metadata") and config._metadata:
self._report.set_data("environment", self._generate_environment(metadata_key))

session.config.hook.pytest_html_report_title(report=self._report)

header_cells = Header()
session.config.hook.pytest_html_results_table_header(cells=header_cells)
self._report.set_data("resultsTableHeader", header_cells.html)
self._report.set_data("headerPops", header_cells.get_pops())
# header_cells = Header
headers = self._report.data["resultsTableHeader"]
session.config.hook.pytest_html_results_table_header(cells=headers)

# self._report.set_data("resultsTableHeader", header_cells.html)
# self._report.set_data("headerPops", header_cells.get_pops())

self._report.set_data("runningState", "Started")
self._generate_report()
Expand All @@ -173,7 +177,8 @@ def pytest_sessionfinish(self, session):
@pytest.hookimpl(trylast=True)
def pytest_terminal_summary(self, terminalreporter):
terminalreporter.write_sep(
"-", f"Generated html report: file://{self._report_path.resolve()}"
"-",
f"Generated html report: file://{self._report_path.resolve().as_posix()}",
)

@pytest.hookimpl(trylast=True)
Expand All @@ -188,31 +193,52 @@ def pytest_runtest_logreport(self, report):
DeprecationWarning,
)

data = {
"duration": report.duration,
}
data = dict()
cells = list()

result = _process_outcome(report)
data["result"] = result
cells.append(f'<td class="col-result">{result}</td>')

test_id = report.nodeid
if report.when != "call":
test_id += f"::{report.when}"
data["testId"] = test_id
cells.append(f'<td class="col-name">{test_id}</td>')

cells.append(f'<td class="col-duration">{report.duration}</td>')
cells.append('<td class="col-links"></td>')

# headers = self._report.data["resultsTableHeader"]
# row = Row.from_headers(headers)
# data = {
# "duration": report.duration,
# }
# row.set("duration", value=data["duration"])

row_cells = Row()
self._config.hook.pytest_html_results_table_row(report=report, cells=row_cells)
if row_cells.html is None:
return
data["resultsTableRow"] = row_cells.html
for sortable, value in row_cells.sortables.items():
data[sortable] = value
# test_id = report.nodeid
# if report.when != "call":
# test_id += f"::{report.when}"
# data["testId"] = test_id
# row.set("test", value=data["testId"])

# data["result"] = _process_outcome(report)
# row.set("result", value=data["result"])

data["extras"] = self._process_extras(report, test_id)
# row.set("links", value=data["extras"])

self._config.hook.pytest_html_results_table_row(report=report, cells=cells)
# if not row:
# return
# ROW CAN PROBABLY REPLACE data
data["resultsTableRow"] = cells

processed_logs = _process_logs(report)
self._config.hook.pytest_html_results_table_html(
report=report, data=processed_logs
)

data["result"] = _process_outcome(report)
data["extras"] = self._process_extras(report, test_id)

if self._report.add_test(data, report, processed_logs):
self._generate_report()

Expand Down
18 changes: 17 additions & 1 deletion src/pytest_html/report_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@

from pytest_html.util import _handle_ansi

# from pytest_html.table import Header


class ReportData:
def __init__(self, config):
self._config = config

default_headers = [
'<th class="sortable" data-column-type="result">"Result"</th>',
'<th class="sortable" data-column-type="testId">"Test"</th>',
'<th class="sortable" data-column-type="duration">"Duration"</th>',
'<th>"Links"</th>',
]

# default_headers = Header()
# default_headers.new("0", "result", sortable=True, _deletable=False)
# default_headers.new("1", "test", sortable=True)
# default_headers.new("2", "duration", sortable=True)
# default_headers.new("3", "links")

self._data = {
"title": "",
"collectedItems": 0,
"runningState": "not_started",
"environment": {},
"tests": defaultdict(list),
"resultsTableHeader": {},
"additionalSummary": defaultdict(list),
"resultsTableHeader": default_headers,
}

collapsed = config.getini("render_collapsed")
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_html/resources/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8302d2e

Please sign in to comment.