Missing data in HTML report table after upgrading to pytest-html 4.1.1
Opened this issue · 5 comments
Hi Team,
I'm currently encountering a problem with pytest-html after upgrading from version 3.2.0 to 4.1.1. My HTML reports are now empty when running tagged tests, although untagged tests generate reports correctly.
Environment: Python version: 3.10 pytest version: 7.4.4 pytest-html version: 4.1.1 (previously 3.2.0)
I'm suspecting since pytest_html_results_table_header hook is not invoking in pytest-html 4.1.1 when running tests with tags. With pytest_html_results_table_header hook I’m trying to insert a snapshot column for failed test , since the table is not properly customized I'm getting an empty report. This hook was invoked in the previous version and is still invoking in 4.1.1 when running tests without tags. The lack of this hook prevents proper table customization, resulting in an empty table.
Observed Behavior: The HTML report's results table is empty when running the tests with tags.
Expected Behavior: The results table should display all test results (name, outcome, duration), including the newer column 'snapshot' when running the tests with tags.
If you have a moment, I'd appreciate your help.
Could you create a small reproducible example?
Also, please dump any output in the browser console here.
Thanks 🙏🏼
Example unit test:
import pytest
@pytest.mark.tags('html_report')
def test_failing_example():
assert 1 == 2`
conftest.py
import pytest
@pytest.hookimpl(tryfirst=True)
def pytest_html_results_table_header(cells):
cells.insert(3, html.th("snapshot", class_="sortable", col="snapshot"))
@pytest.hookimpl(tryfirst=True)
def pytest_html_results_table_row(report, cells):
#code
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_htmlreport(item,call):
outcome = yield
# code
Run command :
python run.py —tags=html_report - with tags -issues with latest version4.1.1, But when i downgraded to 3.2.0 got html table table with data as expected.
python run.py tests/test_pytest_html.py - without tags -no issues with both the versions
**Got INTERNALERROR : **
`INTERNALERROR> File ".nox/tests/lib/python3.10/site-packages/pytest_html/basereport.py", line 245, in pytest_runtest_logreport
INTERNALERROR> self._process_report(each, dur)
INTERNALERROR> File ".nox/tests/lib/python3.10/site-packages/pytest_html/basereport.py", line 283, in _process_report
INTERNALERROR> self._hydrate_data(data, cells)
INTERNALERROR> File ".nox/tests/lib/python3.10/site-packages/pytest_html/basereport.py", line 159, in _hydrate_data
INTERNALERROR> if "sortable" in self._report.table_header[index]:
INTERNALERROR> IndexError: list index out of range`
I'm suspecting the way to invoking this pytest_html_results_table_header while run the tests with tags is changed in the latest version
What is run.py
?
What happens if you run it with pytest
?
Where does the --tags
flag come from?
pytest
I am experiencing the same behavior when I run with pytest as well...
Pytest command :pytest --color=yes --tags=pytest_html
--tags
these tags were configured in another file
def pytest_addoption(parser):
parser.addoption("--tags", nargs="+", metavar="TAG", help="Tags to filter tests")
def pytest_configure(config):
# configured using config.getoption("--tags")
def pytest_collection_modifyitems(items, config):
tags = config.option.tags
if tags:
selected_items = [item for item in items if any(tag in item.keywords for tag in tags)]
items[:] = selected_items
I'm suspecting this issue is with the pytest_html_results_table_header hook after upgrading to pytest-html 4.1.1. In version 3.2.0, this hook was called during pytest_sessionfinish, but it now appears to be called during pytest_sessionstart in the latest version. But the pytest_sessionstart itself is not invoked.
Could you please suggest how to invoke pytest_sessionstart from my current setup, and also let me know if I can customize the HTML report header in any other way?
I am also facing the same issue as pytest_html_results_table_header and pytest_html_report_title fixtures get called first instead of at the end of the session while generating report.
The last stable version where the test report got generated successfully is pytest-html==3.2.0.