From d5d4812ca6f365bc9479b9bab47547297fd3499e Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 10 Oct 2023 11:15:27 +0300 Subject: [PATCH] Fix: Crash on _hydrate_data Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/_pytest/main.py", line 271, in wrap_session session.exitstatus = doit(config, session) or 0 ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/_pytest/main.py", line 325, in _main config.hook.pytest_runtestloop(session=session) File "/usr/local/lib/python3.11/dist-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 152, in _multicall return outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/_pytest/main.py", line 350, in pytest_runtestloop item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) File "/usr/local/lib/python3.11/dist-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 152, in _multicall return outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_result.py", line 114, in get_result raise exc.with_traceback(exc.__traceback__) File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pytest_rerunfailures.py", line 622, in pytest_runtest_protocol item.ihook.pytest_runtest_logreport(report=report) File "/usr/local/lib/python3.11/dist-packages/pluggy/_hooks.py", line 493, in __call__ return self._hookexec(self.name, self._hookimpls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_manager.py", line 115, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 113, in _multicall raise exception.with_traceback(exception.__traceback__) File "/usr/local/lib/python3.11/dist-packages/pluggy/_callers.py", line 77, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pytest_html/basereport.py", line 242, in pytest_runtest_logreport self._hydrate_data(data, cells) File "/usr/local/lib/python3.11/dist-packages/pytest_html/basereport.py", line 159, in _hydrate_data if "sortable" in self._report.table_header[index]: ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ IndexError: list index out of range Amends commit abde929fc8. --- src/pytest_html/basereport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index b160e910..e6209682 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -152,9 +152,10 @@ def _run_count(self): return f"{counts}/{self._report.collected_items} {'tests' if plural else 'test'} done." def _hydrate_data(self, data, cells): + table_len = len(self._report.table_header) for index, cell in enumerate(cells): # extract column name and data if column is sortable - if "sortable" in self._report.table_header[index]: + if index < table_len and "sortable" in self._report.table_header[index]: name_match = re.search(r"col-(\w+)", cell) data_match = re.search(r"(.*?)", cell) if name_match and data_match: