Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate html report using collection modifiers through markers #852

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
14 changes: 12 additions & 2 deletions src/pytest_html/basereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def _run_count(self):

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]:
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"<td.*?>(.*?)</td>", cell)
if name_match and data_match:
Expand All @@ -180,6 +180,16 @@ def pytest_sessionstart(self, session):

@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"],
Expand Down
5 changes: 5 additions & 0 deletions src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down