def start_test(name, attributes):
    test = Test(name=name, attributes=attributes)
    logging.debug("ReportPortal - Start Test: {0}".format(attributes))
    parent_item_id = items[-1][0]
    items.append((RobotService.start_test(
        test=test,
        parent_item_id=parent_item_id,
        attributes=gen_attributes(Variables.test_attributes + test.tags),
    ), parent_item_id))
    def _attributes(self, item):
        attrs = []
        if item.tags:
            significant_tags = [
                t for t in item.tags
                if not any(t.startswith(p) for p in self._ignore_tag_prefixes)
            ]
            attrs.extend(significant_tags)
            attrs.extend(self._get_attributes_from_tags(item.tags))

        return gen_attributes(attrs)
def start_launch(launch):
    """Start a new launch at the Report Portal."""
    if not Variables.launch_id:
        launch.doc = Variables.launch_doc
        logging.debug("ReportPortal - Start Launch: {0}".format(
            launch.attributes))
        RobotService.start_launch(launch_name=Variables.launch_name,
                                  attributes=gen_attributes(
                                      Variables.launch_attributes),
                                  description=launch.doc)
    else:
        RobotService.rp.launch_id = Variables.launch_id

    if Variables.re_run == "yes":
        RobotService.start_launch(launch_name=Variables.launch_name,
                                  attributes=gen_attributes(
                                      Variables.launch_attributes),
                                  description=launch.doc,
                                  rerun=True,
                                  rerunOf=Variables.launch_id)
示例#4
0
 def start_test(self, name, attributes):
     test = Test(name=name, attributes=attributes)
     self._logger.debug("ReportPortal - Start Test: {0}".format(attributes))
     parent_item_id = self.items[-1][0]
     self.items.append((RobotService.start_test(
         test=test,
         start_time=test.start_time,
         parent_item_id=parent_item_id,
         attributes=gen_attributes(Variables.test_attributes) +
         self._gen_attributes_from_robot_tags(test.tags),
     ), parent_item_id))
    def end_test(self, _, attributes, ts=None):
        """Finish started test case at the Report Portal.

        :param attributes: Dictionary passed by the Robot Framework
        :param ts:         Timestamp(used by the ResultVisitor)
        """
        test = self._finish_current_item().update(attributes)
        test.attributes = gen_attributes(self.variables.test_attributes +
                                         test.tags)
        if not test.critical and test.status == 'FAIL':
            test.status = 'SKIP'
        logger.debug('ReportPortal - End Test: {0}'.format(test.attributes))
        self.service.finish_test(test=test, ts=ts)
示例#6
0
 def start_launch(self, launch):
     """Start a new launch at the Report Portal."""
     if not Variables.launch_id:
         launch.doc = Variables.launch_doc
         self._logger.debug("ReportPortal - Start Launch: {0}".format(
             launch.attributes))
         RobotService.start_launch(launch_name=Variables.launch_name,
                                   start_time=launch.start_time,
                                   attributes=gen_attributes(
                                       Variables.launch_attributes),
                                   description=launch.doc)
     else:
         RobotService.rp.launch_id = Variables.launch_id
示例#7
0
    def _build_start_launch_rq(self):
        rp_launch_attributes = self._config.rp_launch_attributes
        attributes = gen_attributes(rp_launch_attributes) \
            if rp_launch_attributes else None

        start_rq = {
            'attributes': self._get_launch_attributes(attributes),
            'name': self._config.rp_launch,
            'start_time': timestamp(),
            'description': self._config.rp_launch_description,
            'mode': self._config.rp_mode,
            'rerun': self._config.rp_rerun,
            'rerun_of': self._config.rp_rerun_of
        }
        return start_rq
def end_suite(_, attributes):
    suite = Suite(attributes=attributes)
    if suite.robot_id == "s1":
        logging.debug(msg="ReportPortal - End Launch: {0}".format(attributes))
        if Variables.re_run != "no":
            RobotService.start_launch(launch_name=Variables.launch_name,
                                      attributes=gen_attributes(
                                          Variables.launch_attributes),
                                      description=suite.doc,
                                      rerun=True,
                                      rerunOf=Variables.launch_id)
        RobotService.finish_launch(launch=suite)
        RobotService.terminate_service()
    else:
        logging.debug("ReportPortal - End Suite: {0}".format(attributes))
        RobotService.finish_suite(item_id=items.pop()[0], suite=suite)
示例#9
0
def pytest_sessionstart(session):
    """
    Start test session.

    :param session: Session
    :return: None
    """
    if session.config._reportportal_configured is False:
        # Stop now if the plugin is not properly configured
        return
    if is_master(session.config):
        try:
            session.config.py_test_service.init_service(
                project=session.config.getini('rp_project'),
                endpoint=session.config.getini('rp_endpoint'),
                uuid=getenv('RP_UUID') or session.config.getini('rp_uuid'),
                log_batch_size=int(session.config.getini('rp_log_batch_size')),
                is_skipped_an_issue=bool(strtobool(session.config.getini(
                    'rp_is_skipped_an_issue'))),
                ignore_errors=bool(session.config.getini('rp_ignore_errors')),
                custom_launch=session.config.option.rp_launch_id or None,
                ignored_attributes=session.config.getini(
                    'rp_ignore_attributes'),
                verify_ssl=session.config.getini('rp_verify_ssl'),
                retries=int(session.config.getini('retries')),
                parent_item_id=session.config.option.rp_parent_item_id or None,
            )
        except ResponseError as response_error:
            log.warning('Failed to initialize reportportal-client service. '
                        'Reporting is disabled.')
            log.debug(str(response_error))
            session.config.py_test_service.rp = None
            return

        attributes = gen_attributes(
            session.config.getini('rp_launch_attributes'))
        if not session.config.option.rp_launch_id:
            session.config.py_test_service.start_launch(
                session.config.option.rp_launch,
                attributes=attributes,
                description=session.config.option.rp_launch_description,
                rerun=session.config.option.rp_rerun,
                rerun_of=session.config.option.rp_rerun_of
            )
            if session.config.pluginmanager.hasplugin('xdist'):
                wait_launch(session.config.py_test_service.rp)
    def start_test(self, name, attributes, ts=None):
        """Start a new test case at the Report Portal.

        :param name:       Test case name
        :param attributes: Dictionary passed by the Robot Framework
        :param ts:         Timestamp(used by the ResultVisitor)
        """
        if 'source' not in attributes:
            # no 'source' parameter at this level for Robot versions < 4
            attributes = attributes.copy()
            attributes['source'] = getattr(self.current_item, 'source', None)
        test = Test(name=name, attributes=attributes)
        logger.debug('ReportPortal - Start Test: {0}'.format(attributes))
        test.attributes = gen_attributes(self.variables.test_attributes +
                                         test.tags)
        test.rp_parent_item_id = self.parent_id
        test.rp_item_id = self.service.start_test(test=test, ts=ts)
        self._items.append(test)
示例#11
0
def pytest_sessionstart(session):
    """Start test session.

    :param session: Object of the pytest Session class
    """
    if session.config._reportportal_configured is False:
        # Stop now if the plugin is not properly configured
        return
    if is_master(session.config):
        config = session.config
        try:
            config.py_test_service.init_service(
                project=config._reporter_config.rp_project,
                endpoint=config._reporter_config.rp_endpoint,
                uuid=config._reporter_config.rp_uuid,
                log_batch_size=config._reporter_config.rp_log_batch_size,
                ignore_errors=config._reporter_config.rp_ignore_errors,
                custom_launch=config._reporter_config.rp_launch_id,
                ignored_attributes=config._reporter_config.
                rp_ignore_attributes,
                verify_ssl=config._reporter_config.rp_verify_ssl,
                retries=config._reporter_config.rp_retries,
                parent_item_id=config._reporter_config.rp_parent_item_id,
            )
        except ResponseError as response_error:
            log.warning('Failed to initialize reportportal-client service. '
                        'Reporting is disabled.')
            log.debug(str(response_error))
            config.py_test_service.rp = None
            return

        attributes = gen_attributes(
            config._reporter_config.rp_launch_attributes)
        if not config._reporter_config.rp_launch_id:
            config.py_test_service.start_launch(
                config._reporter_config.rp_launch,
                attributes=attributes,
                description=config._reporter_config.rp_launch_description,
                rerun=config._reporter_config.rp_rerun,
                rerun_of=config._reporter_config.rp_rerun_of)
            if config.pluginmanager.hasplugin('xdist'):
                wait_launch(session.config.py_test_service.rp)
示例#12
0
    def start_launch(self, attributes, ts=None):
        """Start a new launch at the Report Portal.

        :param attributes: Dictionary passed by the Robot Framework
        :param ts:         Timestamp(used by the ResultVisitor)
        """
        launch = Launch(self.variables.launch_name, attributes)
        launch.attributes = gen_attributes(self.variables.launch_attributes)
        launch.doc = self.variables.launch_doc or launch.doc
        if not self.variables.launch_id:
            if self.variables.pabot_used:
                raise RobotServiceException(PABOT_WIHOUT_LAUNCH_ID_MSG)
            logger.debug('ReportPortal - Start Launch: {0}'.format(
                launch.attributes))
            self.service.start_launch(
                launch=launch,
                mode=self.variables.mode,
                ts=ts,
                skip_analytics=self.variables.skip_analytics)
        else:
            self.service.rp.launch_id = self.variables.launch_id
示例#13
0
    def _get_item_markers(self, item):
        """
        Get attributes of item.

        :param item: pytest.Item
        :return: list of tags
        """

        # Try to extract names of @pytest.mark.* decorators used for test item
        # and exclude those which present in rp_ignore_attributes parameter
        def get_marker_value(item, keyword):
            try:
                marker = item.get_closest_marker(keyword)
            except AttributeError:
                # pytest < 3.6
                marker = item.keywords.get(keyword)

            marker_values = []
            if marker and marker.args:
                for arg in marker.args:
                    marker_values.append("{}:{}".format(keyword, arg))
            else:
                marker_values.append(keyword)
            # returns a list of strings to accommodate multiple values
            return marker_values

        try:
            get_marker = getattr(item, "get_closest_marker")
        except AttributeError:
            get_marker = getattr(item, "get_marker")

        raw_attrs = []
        for k in item.keywords:
            if get_marker(k) is not None and k not in self.ignored_attributes:
                raw_attrs.extend(get_marker_value(item, k))
        raw_attrs.extend(item.session.config.getini('rp_tests_attributes'))
        return gen_attributes(raw_attrs)
def test_gen_attributes():
    """Test functionality of the gen_attributes function."""
    expected_out = [{'value': 'Tag'}, {'key': 'Key', 'value': 'Value'}]
    out = gen_attributes(['Tag', 'Key:Value', ''])
    assert expected_out == out