Пример #1
0
    def dump_xml(self, output_dir):
        """
        Dumps test result to xml
        """
        self.buffer = False

        with open(os.path.join(output_dir, 'junit.xml'), 'w') as output:            
            document = XMLGenerator(output, 'utf-8')
            document.startDocument()
            document.startElement('testsuites', AttributesImpl({}))

            suites = groupby(self.testInfos, key=lambda test_info: self.test_case_name(test_info.test_method))
            for suite_name, suite in suites:
                document.startElement('testsuite', AttributesImpl({'name' : suite_name}))

                for test_info in suite:
                    document.startElement('testcase', AttributesImpl({
                        'classname' : suite_name,
                        'name' : self.test_method_name(test_info.test_method),
                        'time' : '%3f' % total_seconds(test_info.end_time - test_info.start_time)
                    }))

                    if test_info.result == TestInfo.RESULT.ERROR:
                        document.startElement('error', AttributesImpl({
                            'message' : smart_text(test_info.err[1])
                        }))
                        document.characters(self._exc_info_to_string(test_info.err, test_info.test_method))
                        document.endElement('error')
                    elif test_info.result == TestInfo.RESULT.FAILURE:
                        document.startElement('failure', AttributesImpl({
                            'message' : smart_text(test_info.err[1])
                        }))
                        document.characters(self._exc_info_to_string(test_info.err, test_info.test_method))
                        document.endElement('failure')
                    elif test_info.result == TestInfo.RESULT.UNEXPECTED_SUCCESS:
                        document.startElement('error', AttributesImpl({
                            'message' : 'Unexpected success'
                        }))
                        document.endElement('error')
                    elif test_info.result == TestInfo.RESULT.SKIPPED:
                        document.startElement('skipped', AttributesImpl({}))
                        document.characters(test_info.reason)
                        document.endElement('skipped')

                    if test_info.stdout:
                        document.startElement('system-out', AttributesImpl({}))
                        document.characters(test_info.stdout)
                        document.endElement('system-out')

                    if test_info.stderr:
                        document.startElement('system-err', AttributesImpl({}))
                        document.characters(test_info.stderr)
                        document.endElement('system-err')
                    document.endElement('testcase')

                document.endElement('testsuite')

            document.endElement('testsuites')
            document.endDocument()
Пример #2
0
    def dump_xml(self, output_dir):
        """
        Dumps test result to xml
        """
        self.buffer = False

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        with open(os.path.join(output_dir, 'junit.xml'), 'w') as output:
            document = XMLGenerator(output, 'utf-8')
            document.startDocument()
            document.startElement('testsuites', AttributesImpl({}))

            suites = groupby(self.testInfos,
                             key=lambda test_info: test_info.case_name)
            for suite_name, suite in suites:
                document.startElement('testsuite',
                                      AttributesImpl({'name': suite_name}))

                for test_info in suite:
                    document.startElement(
                        'testcase',
                        AttributesImpl({
                            'classname':
                            suite_name,
                            'name':
                            test_info.method_name,
                            'time':
                            '%3f' % total_seconds(test_info.end_time -
                                                  test_info.start_time)
                        }))

                    if test_info.result == TestInfo.RESULT.ERROR:
                        document.startElement(
                            'error',
                            AttributesImpl(
                                {'message': smart_text(test_info.err[1])}))
                        document.characters(
                            self._exc_info_to_string(test_info.err, test_info))
                        document.endElement('error')
                    elif test_info.result == TestInfo.RESULT.FAILURE:
                        document.startElement(
                            'failure',
                            AttributesImpl(
                                {'message': smart_text(test_info.err[1])}))
                        document.characters(
                            self._exc_info_to_string(test_info.err, test_info))
                        document.endElement('failure')
                    elif test_info.result == \
                                    TestInfo.RESULT.UNEXPECTED_SUCCESS:
                        document.startElement(
                            'error',
                            AttributesImpl({'message': 'Unexpected success'}))
                        document.endElement('error')
                    elif test_info.result == TestInfo.RESULT.SKIPPED:
                        document.startElement('skipped', AttributesImpl({}))
                        document.characters(test_info.reason)
                        document.endElement('skipped')

                    if test_info.stdout:
                        document.startElement('system-out', AttributesImpl({}))
                        document.characters(test_info.stdout)
                        document.endElement('system-out')

                    if test_info.stderr:
                        document.startElement('system-err', AttributesImpl({}))
                        document.characters(test_info.stderr)
                        document.endElement('system-err')
                    document.endElement('testcase')

                document.endElement('testsuite')

            document.endElement('testsuites')
            document.endDocument()