當前位置: 首頁>>代碼示例>>Python>>正文


Python junit_xml.TestSuite方法代碼示例

本文整理匯總了Python中junit_xml.TestSuite方法的典型用法代碼示例。如果您正苦於以下問題:Python junit_xml.TestSuite方法的具體用法?Python junit_xml.TestSuite怎麽用?Python junit_xml.TestSuite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在junit_xml的用法示例。


在下文中一共展示了junit_xml.TestSuite方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_event

# 需要導入模塊: import junit_xml [as 別名]
# 或者: from junit_xml import TestSuite [as 別名]
def handle_event(self, context: ExecutionContext, event: events.ExecutionEvent) -> None:
        if isinstance(event, events.Initialized):
            self.start_time = event.start_time
        if isinstance(event, events.AfterExecution):
            test_case = TestCase(
                f"{event.result.method} {event.result.path}",
                elapsed_sec=event.elapsed_time,
                allow_multiple_subelements=True,
            )
            if event.status == Status.failure:
                checks = get_unique_failures(event.result.checks)
                for idx, check in enumerate(checks, 1):
                    # `check.message` is always not empty for events with `failure` status
                    test_case.add_failure_info(message=f"{idx}. {check.message}")
            if event.status == Status.error:
                test_case.add_error_info(
                    message=event.result.errors[-1].exception, output=event.result.errors[-1].exception_with_traceback
                )
            self.test_cases.append(test_case)
        if isinstance(event, events.Finished):
            test_suites = [TestSuite("schemathesis", test_cases=self.test_cases, hostname=platform.node())]
            to_xml_report_file(file_descriptor=self.file_handle, test_suites=test_suites, prettyprint=True) 
開發者ID:kiwicom,項目名稱:schemathesis,代碼行數:24,代碼來源:junitxml.py

示例2: get_junit_items

# 需要導入模塊: import junit_xml [as 別名]
# 或者: from junit_xml import TestSuite [as 別名]
def get_junit_items(self, new_items=''):
        """
        Convert from canonical data model to junit test suit
        :param new_items:
        :return:
        """
        test_cases = []
        if not self.test_items and not new_items:
            raise ValueError('There it no test items')
        data = self.test_items if not new_items else new_items

        for item in data:
            tc = TestCase(item.issue, classname=item.confidence)
            message = ''
            for msg in item.msgs:
                message = message + msg.message + "\n\n"
            tc.add_error_info(message=message, error_type=item.severity)
            test_cases.append(tc)
        ts = TestSuite(self.report_name, test_cases)
        return ts 
開發者ID:dowjones,項目名稱:reapsaw,代碼行數:22,代碼來源:Converter.py

示例3: main

# 需要導入模塊: import junit_xml [as 別名]
# 或者: from junit_xml import TestSuite [as 別名]
def main() -> None:
    """Generate a JUnit XML file."""

    log = logparser.from_argv()

    toplevels = parse_log(log)
    testcases: typing.List[junit_xml.TestCase] = []
    for i, toplevel in enumerate(toplevels):
        testcases += toplevel_to_junit(i, toplevel)
    print(
        json.dumps(list(map(lambda x: f"{x.classname}", testcases)), indent=4),
        file=sys.stderr,
    )

    print(junit_xml.TestSuite.to_xml_string([junit_xml.TestSuite("tbot", testcases)])) 
開發者ID:Rahix,項目名稱:tbot,代碼行數:17,代碼來源:junit.py

示例4: take_action

# 需要導入模塊: import junit_xml [as 別名]
# 或者: from junit_xml import TestSuite [as 別名]
def take_action(self, args):
        test_cases = []
        if args.playbook is not None:
            playbooks = args.playbook
            results = (models.TaskResult().query
                       .join(models.Task)
                       .filter(models.TaskResult.task_id == models.Task.id)
                       .filter(models.Task.playbook_id.in_(playbooks)))
        else:
            results = models.TaskResult().query.all()

        for result in results:
            task_name = result.task.name
            if not task_name:
                task_name = result.task.action
            additional_results = {
                'host': result.host.name,
                'playbook_path': result.task.playbook.path
            }
            result_str = jsonutils.dumps(additional_results)
            test_path = \
                u'{playbook_file}.{play_name}'.format(
                    playbook_file=os.path.basename(result.task.playbook.path),
                    play_name=result.task.play.name)
            test_case = TestCase(
                name=task_name,
                classname=test_path,
                elapsed_sec=result.duration.seconds,
                stdout=result_str)
            if result.status == 'skipped':
                test_case.add_skipped_info(message=result.result)
            elif (result.status in ('failed', 'unreachable') and
                    result.ignore_errors is False):
                test_case.add_failure_info(message=result.result)
            test_cases.append(test_case)
        test_suite = TestSuite('Ansible Tasks', test_cases)

        # TODO: junit_xml doesn't order the TestCase parameters.
        # This makes it so the order of the parameters for the same exact
        # TestCase is not guaranteed to be the same and thus results in a
        # different stdout (or file). This is easily reproducible on Py3.
        xml_string = six.text_type(test_suite.to_xml_string([test_suite]))
        if args.output_file == '-':
            if six.PY2:
                sys.stdout.write(encodeutils.safe_encode(xml_string))
            else:
                sys.stdout.buffer.write(encodeutils.safe_encode(xml_string))
        else:
            with open(args.output_file, 'wb') as f:
                f.write(encodeutils.safe_encode(xml_string)) 
開發者ID:dmsimard,項目名稱:ara-archive,代碼行數:52,代碼來源:generate.py


注:本文中的junit_xml.TestSuite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。