Instantly share code, notes, and snippets.

@BeyondEvil /conftest.py Secret
Created Apr 28, 2017

Embed
What would you like to do?
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item):
"""
Hook to add items to the html report.
Currently adds the HAR (proxy info) and the python log to the report.
:param item: test item
:return: None
"""
outcome = yield
report = outcome.get_result()
summary = []
extra = getattr(report, 'extra', [])
driver = getattr(item, '_driver', None)
xfail = hasattr(report, 'wasxfail')
failure = (report.skipped and xfail) or (report.failed and not xfail)
when = item.config.getini('selenium_capture_debug').lower()
capture_debug = when == 'always' or (when == 'failure' and failure)
if capture_debug and driver is not None:
if get_config().option.remote:
summary.append('Test ran on node: {}'.format(get_grid_node(driver)))
summary.append('Window size: width <{0[width]}>, height <{0[height]}>'.format(driver.get_window_size()))
pytest_html = item.config.pluginmanager.getplugin('html')
if pytest_html is not None:
# Add HAR to report
if driver.proxy is not None:
try:
har = driver.proxy.har
extra.append(pytest_html.extras.json(har, 'HAR'))
except Exception as e:
summary.append('WARNING: Failed to get HAR: {0}'.format(e))
# Add link to kibana for this session
extra.append(pytest_html.extras.url(get_kibana_url(), 'Kibana'))
if summary:
report.sections.append(('Additional Reporting', '\n'.join(summary)))
report.extra = extra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment