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

Missing data in HTML report table after upgrading to pytest-html 4.1.1 #849

Open
Ramya2801 opened this issue Nov 22, 2024 · 5 comments
Open

Comments

@Ramya2801
Copy link

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.

empty_report

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.

@BeyondEvil
Copy link
Contributor

Could you create a small reproducible example?

Also, please dump any output in the browser console here.

Thanks 🙏🏼

@Ramya2801
Copy link
Author

Ramya2801 commented Nov 22, 2024

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

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Nov 22, 2024

What is run.py?

What happens if you run it with pytest?

Where does the --tags flag come from?

@Ramya2801
Copy link
Author

Ramya2801 commented Nov 25, 2024

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?

@shrutinipane
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants