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

4.1.0 - report not generating data #858

Open
jhickeyBOT opened this issue Jan 27, 2025 · 0 comments
Open

4.1.0 - report not generating data #858

jhickeyBOT opened this issue Jan 27, 2025 · 0 comments

Comments

@jhickeyBOT
Copy link

``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()`

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

1 participant