From 3ae609e00b67dd911f0a24a7ef7f71ccfeabd49f Mon Sep 17 00:00:00 2001 From: Ramya2801 Date: Fri, 6 Dec 2024 18:08:10 +0530 Subject: [PATCH 1/7] Updated basereport.py to invoke pytest_html_results_table_header --- src/pytest_html/basereport.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index cfcc74b..2e22c47 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -180,6 +180,16 @@ class BaseReport: @pytest.hookimpl(trylast=True) def pytest_sessionfinish(self, session): + generate_with_tags = session.config.getoption("generate_reports_with_tags") + self._report.set_data("environment", self._generate_environment()) + session.config.hook.pytest_html_report_title(report=self._report) + if generate_with_tags: + headers = self._report.table_header + session.config.hook.pytest_html_results_table_header(cells=headers) + self._report.table_header = _fix_py(headers) + self._report.running_state = "started" + self._generate_report() + session.config.hook.pytest_html_results_summary( prefix=self._report.additional_summary["prefix"], summary=self._report.additional_summary["summary"], From 53d3cf31af44e601b2a07c536fce4e0f2d13f45a Mon Sep 17 00:00:00 2001 From: Ramya2801 Date: Fri, 6 Dec 2024 18:09:43 +0530 Subject: [PATCH 2/7] Update plugin.py for generating html reports through collection modifiers --- src/pytest_html/plugin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index 949a6ff..d446f9b 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -79,6 +79,12 @@ def pytest_addoption(parser): help="the HTML report will be generated after each test " "instead of at the end of the run.", ) + group.addoption( + "--generate_reports_with_tags", + action="store_true", + help="the HTML report will be generated while running with tags", + + ) def pytest_configure(config): From 042f09e873b38f94c9866f3fd50c9c25bf17d9a4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:45:46 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytest_html/basereport.py | 2 +- src/pytest_html/plugin.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index 2e22c47..8d60e3b 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -189,7 +189,7 @@ class BaseReport: self._report.table_header = _fix_py(headers) self._report.running_state = "started" self._generate_report() - + session.config.hook.pytest_html_results_summary( prefix=self._report.additional_summary["prefix"], summary=self._report.additional_summary["summary"], diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index d446f9b..4268528 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -83,8 +83,7 @@ def pytest_addoption(parser): "--generate_reports_with_tags", action="store_true", help="the HTML report will be generated while running with tags", - - ) + ) def pytest_configure(config): From 3f53b65deda823f0840742360f1054f156a594a8 Mon Sep 17 00:00:00 2001 From: Ramya2801 Date: Fri, 6 Dec 2024 18:35:15 +0530 Subject: [PATCH 4/7] Update plugin.py lint fix --- src/pytest_html/plugin.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index 4268528..2bc59a2 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -48,6 +48,11 @@ def pytest_addoption(parser): default=[], help="append given css file content to report style file.", ) + group.addoption( + "--generate_reports_with_tags", + action="store_true", + help="the HTML report will be generated while running with tags", + ) parser.addini( "render_collapsed", type="string", @@ -79,12 +84,6 @@ def pytest_addoption(parser): help="the HTML report will be generated after each test " "instead of at the end of the run.", ) - group.addoption( - "--generate_reports_with_tags", - action="store_true", - help="the HTML report will be generated while running with tags", - ) - def pytest_configure(config): html_path = config.getoption("htmlpath") From 0b6eacf99f6d54014a03d87f12bbcdfc95c001cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:05:41 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytest_html/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index 2bc59a2..aa17004 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -85,6 +85,7 @@ def pytest_addoption(parser): "instead of at the end of the run.", ) + def pytest_configure(config): html_path = config.getoption("htmlpath") if html_path: From eb3bde0d7a793a582ed14dd4606004c0fb723bde Mon Sep 17 00:00:00 2001 From: Ramya2801 Date: Mon, 9 Dec 2024 18:04:14 +0530 Subject: [PATCH 6/7] Updated basereport.py Updated basereport.py as it is crashed on _hydrate_data --- src/pytest_html/basereport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index 8d60e3b..ef0ff0d 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -156,9 +156,9 @@ class BaseReport: return f"{counts}/{self._report.collected_items} {'tests' if plural else 'test'} done." def _hydrate_data(self, data, cells): - for index, cell in enumerate(cells): - # extract column name and data if column is sortable - if "sortable" in self._report.table_header[index]: + for index, cell in enumerate(cells): + table_len = len(self._report.table_header) + 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: From 8401373925426b4fce7f3827d01ee7f48958ec0d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:34:29 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pytest_html/basereport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_html/basereport.py b/src/pytest_html/basereport.py index ef0ff0d..b648ba8 100644 --- a/src/pytest_html/basereport.py +++ b/src/pytest_html/basereport.py @@ -156,7 +156,7 @@ class BaseReport: return f"{counts}/{self._report.collected_items} {'tests' if plural else 'test'} done." def _hydrate_data(self, data, cells): - for index, cell in enumerate(cells): + for index, cell in enumerate(cells): table_len = len(self._report.table_header) if index < table_len and "sortable" in self._report.table_header[index]: name_match = re.search(r"col-(\w+)", cell)