Skip to content

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

Open

Description

@Ramya2801

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.

Activity

  1. BeyondEvil commented on Nov 22, 2024

    @BeyondEvil
    Contributor

    Could you create a small reproducible example?

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

    Thanks 🙏🏼

  2. Ramya2801 commented on Nov 22, 2024

    @Ramya2801
    Author

    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

  3. BeyondEvil commented on Nov 22, 2024

    @BeyondEvil
    Contributor

    What is run.py?

    What happens if you run it with pytest?

    Where does the --tags flag come from?

  4. Ramya2801 commented on Nov 25, 2024

    @Ramya2801
    Author

    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?

  5. shrutinipane commented on Nov 26, 2024

    @shrutinipane

    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.

  6. a-kleinf commented on Feb 26, 2026

    @a-kleinf

    I encountered the same issue - it appears that the file or folder name affects how the HTML file is rendered in the browser. If the file path contains special characters, such as “ä”, it seems to break the HTML file.

    (Observed with pytest-html versions 4.1.1 and 4.2.0.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions