pytest-dev / pytest-dev/pytest-html

4.1.0 - report not generating data

Open
#858 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

``When using pytest-html 3.2.0, the report generated correctly, showing details of failed tests.

Image

When upgraded to pytest-html-4.1.0, the report no longer showed this data.

Image

By upgrading and downgrading I can make the report work correctly and break it again. The only thing effecting the report generating is the version of pytest-html.

Below is my function for the report:
`@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item):
"""
Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails.
:param item:
"""
pytest_html = item.config.pluginmanager.getplugin('html')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])

# Add rerun information if available
rerun = item.config.option.reruns
if rerun:
    if hasattr(report, "rerun") and report.rerun > 0:
        extra.append(pytest_html.extras.text(f"Rerun Attempt: {report.rerun}", mime_type="text/plain"))

# Embed screenshots for failed or rerun tests
if report.when == 'call' or report.when == "setup":
    xfail = hasattr(report, 'wasxfail')
    if (report.skipped and xfail) or (report.failed and not xfail):
        base64_image = _capture_screenshot()
        if base64_image:
            html = (
                f'<div>'
                f'<img src="data:image/png;base64,{base64_image}" alt="screenshot"'
                f' style="width:304px;height:228px;" onclick="window.open(this.src)" align="right"/>'
                f'</div>'
            )
            extra.append(pytest_html.extras.html(html))

    # Assign updated extras back to the report
    report.extra = extra

def _capture_screenshot():
return driver.get_screenshot_as_base64()`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported pytest_runtest_makereport hook and compare its behavior with pytest-html 3.2.0 and 4.1.0. Reproduce the report-generation difference using the supplied screenshot and rerun-extra logic; done means failed-test details and embedded extras appear in the generated report.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.