Ejemplo n.º 1
0
def pytest_exception_interact(node, call, report):
    from cfme.fixtures.pytest_store import store
    from six.moves.http_client import BadStatusLine
    from socket import error

    val = safe_string(call.excinfo.value)
    if isinstance(call.excinfo.value, (URLError, BadStatusLine, error)):
        logger.error("internal Exception:\n %s", str(call.excinfo))
        from cfme.utils.browser import manager
        manager.start()  # start will quit first and cycle wharf as well

    last_lines = "\n".join(report.longreprtext.split("\n")[-4:])

    short_tb = '{}\n{}\n{}'.format(
        last_lines, call.excinfo.type.__name__,
        val.encode('ascii', 'xmlcharrefreplace')
    )
    fire_art_test_hook(
        node, 'filedump',
        description="Traceback", contents=report.longreprtext, file_type="traceback",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=store.slaveid)
    fire_art_test_hook(
        node, 'filedump',
        description="Short traceback", contents=short_tb, file_type="short_tb",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=store.slaveid)
    exception_name = call.excinfo.type.__name__
    exception_lineno = call.excinfo.traceback[-1].lineno
    exception_filename = str(call.excinfo.traceback[-1].path).replace(
        project_path.strpath + "/", ''
    )
    exception_location = "{}:{}".format(exception_filename, exception_lineno)
    fire_art_test_hook(
        node, 'tb_info',
        exception=exception_name, file_line=exception_location,
        short_tb=short_tb, slave_id=store.slaveid
    )

    # base64 encoded to go into a data uri, same for screenshots
    tb = report.longreprtext
    if not isinstance(tb, six.binary_type):
        tb = tb.encode('utf-8')
    full_tb = base64.b64encode(tb)
    # errors are when exceptions are thrown outside of the test call phase
    report.when = getattr(report, 'when', 'setup')
    is_error = report.when != 'call'

    template_data = {
        'name': node.name,
        'file': node.fspath,
        'is_error': is_error,
        'fail_stage': report.when,
        'short_tb': short_tb,
        'full_tb': full_tb,
    }

    # Before trying to take a screenshot, we used to check if one of the browser_fixtures was
    # in this node's fixturenames, but that was too limited and preventing the capture of
    # screenshots. If removing that conditional now makes this too broad, we should consider
    # an isinstance(val, WebDriverException) check in addition to the browser fixture check that
    # exists here in commit 825ef50fd84a060b58d7e4dc316303a8b61b35d2

    screenshot = take_screenshot()
    template_data['screenshot'] = screenshot.png
    template_data['screenshot_error'] = screenshot.error
    if screenshot.png:
        fire_art_test_hook(
            node, 'filedump',
            description="Exception screenshot", file_type="screenshot", mode="wb",
            contents_base64=True, contents=template_data['screenshot'], display_glyph="camera",
            group_id="pytest-exception", slaveid=store.slaveid)
    if screenshot.error:
        fire_art_test_hook(
            node, 'filedump',
            description="Screenshot error", mode="w", contents_base64=False,
            contents=template_data['screenshot_error'], display_type="danger",
            group_id="pytest-exception", slaveid=store.slaveid)

    failed_test_tracking['tests'].append(template_data)
    if is_error:
        failed_test_tracking['total_errored'] += 1
    else:
        failed_test_tracking['total_failed'] += 1
Ejemplo n.º 2
0
def pytest_exception_interact(node, call, report):
    from fixtures.pytest_store import store
    from six.moves.http_client import BadStatusLine
    from socket import error

    val = safe_string(call.excinfo.value.message).decode('utf-8', 'ignore')
    if isinstance(call.excinfo.value, (URLError, BadStatusLine, error)):
        logger.error("internal Exception:\n %s", str(call.excinfo))
        from cfme.utils.browser import manager
        manager.start()  # start will quit first and cycle wharf as well

    last_lines = "\n".join(report.longreprtext.split("\n")[-4:])

    short_tb = '{}\n{}\n{}'.format(
        last_lines, call.excinfo.type.__name__,
        val.encode('ascii', 'xmlcharrefreplace')
    )
    fire_art_test_hook(
        node, 'filedump',
        description="Traceback", contents=report.longreprtext, file_type="traceback",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=store.slaveid)
    fire_art_test_hook(
        node, 'filedump',
        description="Short traceback", contents=short_tb, file_type="short_tb",
        display_type="danger", display_glyph="align-justify", group_id="pytest-exception",
        slaveid=store.slaveid)
    exception_name = call.excinfo.type.__name__
    exception_lineno = call.excinfo.traceback[-1].lineno
    exception_filename = str(call.excinfo.traceback[-1].path).replace(
        project_path.strpath + "/", ''
    )
    exception_location = "{}:{}".format(exception_filename, exception_lineno)
    fire_art_test_hook(
        node, 'tb_info',
        exception=exception_name, file_line=exception_location,
        short_tb=short_tb, slave_id=store.slaveid
    )

    # base64 encoded to go into a data uri, same for screenshots
    full_tb = report.longreprtext.encode('base64').strip()
    # errors are when exceptions are thrown outside of the test call phase
    report.when = getattr(report, 'when', 'setup')
    is_error = report.when != 'call'

    template_data = {
        'name': node.name,
        'file': node.fspath,
        'is_error': is_error,
        'fail_stage': report.when,
        'short_tb': short_tb,
        'full_tb': full_tb,
    }

    # Before trying to take a screenshot, we used to check if one of the browser_fixtures was
    # in this node's fixturenames, but that was too limited and preventing the capture of
    # screenshots. If removing that conditional now makes this too broad, we should consider
    # an isinstance(val, WebDriverException) check in addition to the browser fixture check that
    # exists here in commit 825ef50fd84a060b58d7e4dc316303a8b61b35d2

    screenshot = take_screenshot()
    template_data['screenshot'] = screenshot.png
    template_data['screenshot_error'] = screenshot.error
    if screenshot.png:
        fire_art_test_hook(
            node, 'filedump',
            description="Exception screenshot", file_type="screenshot", mode="wb",
            contents_base64=True, contents=template_data['screenshot'], display_glyph="camera",
            group_id="pytest-exception", slaveid=store.slaveid)
    if screenshot.error:
        fire_art_test_hook(
            node, 'filedump',
            description="Screenshot error", mode="w", contents_base64=False,
            contents=template_data['screenshot_error'], display_type="danger",
            group_id="pytest-exception", slaveid=store.slaveid)

    failed_test_tracking['tests'].append(template_data)
    if is_error:
        failed_test_tracking['total_errored'] += 1
    else:
        failed_test_tracking['total_failed'] += 1