-
Notifications
You must be signed in to change notification settings - Fork 249
Description
``When using pytest-html 3.2.0, the report generated correctly, showing details of failed tests.
When upgraded to pytest-html-4.1.0, the report no longer showed this data.
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()`