Exemplo n.º 1
0
 def __init__(self, cfg, rp_service=None):
     """Initialize instance attributes."""
     self._rp = rp_service
     self._cfg = cfg
     self._launch_id = None
     self._feature_id = None
     self._scenario_id = None
     self._step_id = None
     self._log_item_id = None
     self._skip_analytics = getenv("AGENT_NO_ANALYTICS")
     self.agent_name = "behave-reportportal"
     self.agent_version = get_package_version(self.agent_name)
     # these tags are ignored during collection of test attributes
     # there are other rules for processing of these tags
     self._ignore_tag_prefixes = ["attribute", "fixture", "test_case_id"]
Exemplo n.º 2
0
 def __init__(self, agent_config):
     """Initialize instance attributes."""
     self._config = agent_config
     self._issue_types = {}
     self._tree_path = {}
     self._log_levels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR')
     self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
     self._start_tracker = set()
     self._process_level_lock = threading.Lock()
     self._launch_id = None
     self.agent_name = 'pytest-reportportal'
     self.agent_version = get_package_version(self.agent_name)
     self.ignored_attributes = []
     self.log_batch_size = 20
     self.parent_item_id = None
     self.rp = None
     self.project_settings = {}
Exemplo n.º 3
0
 def __init__(self):
     """Initialize instance attributes."""
     self._errors = queue.Queue()
     self._hier_parts = {}
     self._issue_types = {}
     self._item_parts = {}
     self._loglevels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR')
     self._skip_analytics = getenv('AGENT_NO_ANALYTICS')
     self.agent_name = 'pytest-reportportal'
     self.agent_version = get_package_version(self.agent_name)
     self.ignore_errors = True
     self.ignored_attributes = []
     self.log_batch_size = 20
     self.log_item_id = None
     self.parent_item_id = None
     self.rp = None
     self.rp_supports_parameters = True
     try:
         pkg_resources.get_distribution('reportportal_client >= 3.2.0')
     except pkg_resources.VersionConflict:
         self.rp_supports_parameters = False
def test_get_package_version():
    """Test for the get_package_version() function-helper."""
    assert get_package_version('noname') == 'not found'
Exemplo n.º 5
0
 def __init__(self):
     """Initialize service attributes."""
     self.agent_name = 'robotframework-reportportal'
     self.agent_version = get_package_version(self.agent_name)
     self.rp = None
class RobotService(object):
    agent_name = "robotframework-reportportal"
    agent_version = get_package_version(agent_name)
    rp = None

    status_mapping = {"PASS": "******", "FAIL": "FAILED", "SKIP": "SKIPPED"}

    log_level_mapping = {
        "INFO": "INFO",
        "FAIL": "ERROR",
        "TRACE": "TRACE",
        "DEBUG": "DEBUG",
        "HTML": "INFO",
        "WARN": "WARN",
        "ERROR": "ERROR"
    }

    @staticmethod
    def _get_launch_attributes(cmd_attrs):
        """Generate launch attributes including both system and user ones.

        :param list cmd_attrs: List for attributes from the command line
        """
        attributes = cmd_attrs or []
        system_attributes = get_launch_sys_attrs()
        system_attributes['agent'] = ('{}-{}'.format(
            RobotService.agent_name, RobotService.agent_version))
        return attributes + _dict_to_payload(system_attributes)

    @staticmethod
    def init_service(endpoint, project, uuid, log_batch_size, pool_size):
        if RobotService.rp is None:
            logging.debug("ReportPortal - Init service: "
                          "endpoint={0}, project={1}, uuid={2}".format(
                              endpoint, project, uuid))
            RobotService.rp = ReportPortalService(
                endpoint=endpoint,
                project=project,
                token=uuid,
                log_batch_size=log_batch_size,
                max_pool_size=pool_size)
        else:
            raise Exception("RobotFrameworkService is already initialized")

    @staticmethod
    def terminate_service():
        if RobotService.rp is not None:
            RobotService.rp.terminate()

    @staticmethod
    def start_launch(launch_name,
                     attributes=None,
                     description=None,
                     mode=None):
        """Call start_launch method of the common client.

        :param launch_name: Launch name
        :param attributes:  Launch attributes
        :param description: Launch description
        :param mode:        Launch mode
        :return:            launch UUID
        """
        sl_pt = {
            "attributes": RobotService._get_launch_attributes(attributes),
            "name": launch_name,
            "start_time": timestamp(),
            "description": description,
            "mode": mode
        }
        logging.debug("ReportPortal - Start launch: "
                      "request_body={0}".format(sl_pt))
        if not Variables.skip_analytics:
            send_event(RobotService.agent_name, RobotService.agent_version)
        return RobotService.rp.start_launch(**sl_pt)

    @staticmethod
    def finish_launch(launch=None):
        fl_rq = {
            "end_time": timestamp(),
            "status": RobotService.status_mapping[launch.status]
        }
        logging.debug("ReportPortal - Finish launch: "
                      "request_body={0}".format(fl_rq))
        RobotService.rp.finish_launch(**fl_rq)

    @staticmethod
    def start_suite(name=None,
                    suite=None,
                    parent_item_id=None,
                    attributes=None):
        start_rq = {
            "name": name,
            "attributes": attributes,
            "description": suite.doc,
            "start_time": timestamp(),
            "item_type": "SUITE",
            "parent_item_id": parent_item_id
        }
        logging.debug("ReportPortal - Start suite: "
                      "request_body={0}".format(start_rq))
        return RobotService.rp.start_test_item(**start_rq)

    @staticmethod
    def finish_suite(item_id, issue=None, suite=None):
        fta_rq = {
            "end_time": timestamp(),
            "status": RobotService.status_mapping[suite.status],
            "issue": issue,
            "item_id": item_id
        }
        logging.debug("ReportPortal - Finish suite:"
                      " request_body={0}".format(fta_rq))
        RobotService.rp.finish_test_item(**fta_rq)

    @staticmethod
    def start_test(test=None, parent_item_id=None, attributes=None):
        # Item type should be sent as "STEP" until we upgrade to RPv6.
        # Details at: https://github.com/reportportal/agent-Python-RobotFramework/issues/56
        start_rq = {
            "name": test.name,
            "attributes": attributes,
            "description": test.doc,
            "start_time": timestamp(),
            "item_type": "STEP",
            "parent_item_id": parent_item_id
        }
        logging.debug("ReportPortal - Start test: "
                      "request_body={0}".format(start_rq))
        return RobotService.rp.start_test_item(**start_rq)

    @staticmethod
    def finish_test(item_id, issue=None, test=None):
        fta_rq = {
            "end_time": timestamp(),
            "status": RobotService.status_mapping[test.status],
            "issue": issue,
            "item_id": item_id
        }
        logging.debug("ReportPortal - Finish test:"
                      " request_body={0}".format(fta_rq))
        RobotService.rp.finish_test_item(**fta_rq)

    @staticmethod
    def start_keyword(keyword=None, parent_item_id=None, has_stats=True):
        start_rq = {
            "name": keyword.get_name(),
            "description": keyword.doc,
            "start_time": timestamp(),
            "item_type": keyword.get_type(),
            "parent_item_id": parent_item_id,
            "has_stats": has_stats
        }
        logging.debug("ReportPortal - Start keyword: "
                      "request_body={0}".format(start_rq))
        return RobotService.rp.start_test_item(**start_rq)

    @staticmethod
    def finish_keyword(item_id, issue=None, keyword=None):
        fta_rq = {
            "end_time": timestamp(),
            "status": RobotService.status_mapping[keyword.status],
            "issue": issue,
            "item_id": item_id
        }
        logging.debug("ReportPortal - Finish keyword:"
                      " request_body={0}".format(fta_rq))
        RobotService.rp.finish_test_item(**fta_rq)

    @staticmethod
    def log(message):
        sl_rq = {
            "time": timestamp(),
            "message": message.message,
            "level": RobotService.log_level_mapping[message.level],
            "attachment": message.attachment,
            "item_id": message.item_id
        }
        RobotService.rp.log(**sl_rq)