Skip to content

Commit

Permalink
Fix: Handle legacy py html (pytest-dev#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored Jul 23, 2023
1 parent 7ff7703 commit cb09706
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def pytest_sessionstart(self, session):

headers = self._report.data["resultsTableHeader"]
session.config.hook.pytest_html_results_table_header(cells=headers)
self._report.data["resultsTableHeader"] = _fix_py(headers)

self._report.set_data("runningState", "Started")
self._generate_report()
Expand Down Expand Up @@ -216,6 +217,7 @@ def pytest_runtest_logreport(self, report):
if not cells:
return

cells = _fix_py(cells)
data["resultsTableRow"] = cells

processed_logs = _process_logs(report)
Expand Down Expand Up @@ -279,3 +281,20 @@ def _process_outcome(report):
def _process_links(links):
a_tag = '<a target="_blank" href="{content}" class="col-links__extra {format_type}">{name}</a>'
return "".join([a_tag.format_map(link) for link in links])


def _fix_py(cells):
# backwards-compat
new_cells = []
for html in cells:
if not isinstance(html, str):
if html.__module__.startswith("py."):
warnings.warn(
"The 'py' module is deprecated and support "
"will be removed in a future release.",
DeprecationWarning,
)
html = str(html)
html = html.replace("col=", "data-column-type=")
new_cells.append(html)
return new_cells

0 comments on commit cb09706

Please sign in to comment.