From a9f218d400a9193972ed5042d16bbaab7efb3329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Sun, 23 Jul 2023 23:38:38 +0200 Subject: [PATCH] Fix: Handle legacy py html --- src/pytest_html/basereport.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index df6bc3f2..50b17e57 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -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() @@ -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) @@ -279,3 +281,20 @@ def _process_outcome(report): def _process_links(links): a_tag = '{name}' 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