Example #1
0
    def __init__(self, build: Build) -> None:
        """
        Creates a container class for a Jenkins Build object.

        Attributes:
         - timestamp: Build timestamp in UTC
         - number: Build number
         - failed: False if build was successful, True if not
         - failed_tests: List of failed test names

        :param build: A Build object from the Jenkins server
        """

        self.timestamp = build.get_timestamp().strftime('%m-%d-%Y %I:%M %p')
        self.number = build.get_number()

        self.status = build.get_status()
        if self.status == 'SUCCESS':
            self.failed = False
        else:
            self.failed = True

        self.failed_tests = []  # type: List[str]
        self.test_count = 0
        self.fail_count = 0

        if self.status != 'ABORTED' and build.has_resultset():
            self.test_count = build.get_actions()['totalCount']
            self.fail_count = build.get_actions()['failCount']

            result_set = build.get_resultset()

            for _, result in result_set.iteritems():
                test_name = result.identifier()

                if result.status == 'FAILED' or result.status == 'REGRESSION':
                    self.failed_tests.append(test_name)