xunitgen/main.py
def toxml(test_reports, suite_name,
          hostname=gethostname(), package_name="tests"):
    """convert test reports into an xml file"""

    testsuites = et.Element("testsuites")
    testsuite = et.SubElement(testsuites, "testsuite")

    test_count = len(test_reports)
    if test_count < 1:
        raise ValueError('there must be at least one test report')


    assert test_count > 0, 'expecting at least one test'

    error_count = len([r for r in test_reports if r.errors])
    failure_count = len([r for r in test_reports if r.failures])
    ts = test_reports[0].start_ts
    start_timestamp = datetime.fromtimestamp(ts).isoformat()

    total_duration = test_reports[-1].end_ts - test_reports[0].start_ts

    def quote_attribute(value):
        return value if value is not None else "(null)"


    testsuite.attrib = dict(
        id="0",
        errors=str(error_count),
        failures=str(failure_count),
        tests=str(test_count),
        hostname=quote_attribute(hostname),
        timestamp=quote_attribute(start_timestamp),
        time="%f" % total_duration,
        name=quote_attribute(suite_name),
        package=quote_attribute(package_name),
    )

    for r in test_reports:
        test_name = r.name
        test_duration = r.end_ts - r.start_ts
        class_name = r.src_location

        testcase = et.SubElement(testsuite, "testcase")
        testcase.attrib = dict(
            name=test_name,
            classname=quote_attribute(class_name),
            time="%f" % test_duration,
            )
        if r.errors or r.failures:
            if r.failures:
                failure = et.SubElement(testcase, "failure")
                failure.attrib = dict(
                    type="exception",
                    message=quote_attribute('\n'.join(['%s' % e for e in r.failures])),
                )
            else:
                error = et.SubElement(testcase, "error")
                error.attrib = dict(
                    type="exception",
                    message=quote_attribute('\n'.join(['%s' % e for e in r.errors])),
                )

    return et.tostring(testsuites, encoding="utf-8")
def toxml(test_reports, suite_name,
          hostname=gethostname(), package_name="tests"):
    testsuites = et.Element("testsuites")
    testsuite = et.SubElement(testsuites, "testsuite")

    test_count = len(test_reports)
    if test_count < 1:
        raise ValueError('there must be at least one test report')


    assert test_count > 0, 'expecting at least one test'

    error_count = len([r for r in test_reports if r.errors])
    failure_count = len([r for r in test_reports if r.failures])
    ts = test_reports[0].start_ts
    start_timestamp = datetime.fromtimestamp(ts).isoformat()

    total_duration = test_reports[-1].end_ts - test_reports[0].start_ts

    def quote_attribute(value):
        return value if value is not None else "(null)"


    testsuite.attrib = dict(
        id="0",
        errors=str(error_count),
        failures=str(failure_count),
        tests=str(test_count),
        hostname=quote_attribute(hostname),
        timestamp=quote_attribute(start_timestamp),
        time="%f" % total_duration,
        name=quote_attribute(suite_name),
        package=quote_attribute(package_name),
    )

    for r in test_reports:
        test_name = r.name
        test_duration = r.end_ts - r.start_ts
        class_name = r.src_location

        testcase = et.SubElement(testsuite, "testcase")
        testcase.attrib = dict(
            name=test_name,
            classname=quote_attribute(class_name),
            time="%f" % test_duration,
            )
        if r.errors or r.failures:
            if r.failures:
                failure = et.SubElement(testcase, "failure")
                failure.attrib = dict(
                    type="exception",
                    message=quote_attribute('\n'.join(['%s' % e for e in r.failures])),
                )
            else:
                error = et.SubElement(testcase, "error")
                error.attrib = dict(
                    type="exception",
                    message=quote_attribute('\n'.join(['%s' % e for e in r.errors])),
                )

    return et.tostring(testsuites, encoding="utf-8")
def toxml ( test_reports , suite_name , hostname = gethostname ( ) , package_name = "tests" ) : testsuites = et . Element ( "testsuites" ) testsuite = et . SubElement ( testsuites , "testsuite" ) test_count = len ( test_reports ) if test_count < 1 : raise ValueError ( 'there must be at least one test report' ) assert test_count > 0 , 'expecting at least one test' error_count = len ( [ r for r in test_reports if r . errors ] ) failure_count = len ( [ r for r in test_reports if r . failures ] ) ts = test_reports [ 0 ] . start_ts start_timestamp = datetime . fromtimestamp ( ts ) . isoformat ( ) total_duration = test_reports [ - 1 ] . end_ts - test_reports [ 0 ] . start_ts def quote_attribute ( value ) : return value if value is not None else "(null)" testsuite . attrib = dict ( id = "0" , errors = str ( error_count ) , failures = str ( failure_count ) , tests = str ( test_count ) , hostname = quote_attribute ( hostname ) , timestamp = quote_attribute ( start_timestamp ) , time = "%f" % total_duration , name = quote_attribute ( suite_name ) , package = quote_attribute ( package_name ) , ) for r in test_reports : test_name = r . name test_duration = r . end_ts - r . start_ts class_name = r . src_location testcase = et . SubElement ( testsuite , "testcase" ) testcase . attrib = dict ( name = test_name , classname = quote_attribute ( class_name ) , time = "%f" % test_duration , ) if r . errors or r . failures : if r . failures : failure = et . SubElement ( testcase , "failure" ) failure . attrib = dict ( type = "exception" , message = quote_attribute ( '\n' . join ( [ '%s' % e for e in r . failures ] ) ) , ) else : error = et . SubElement ( testcase , "error" ) error . attrib = dict ( type = "exception" , message = quote_attribute ( '\n' . join ( [ '%s' % e for e in r . errors ] ) ) , ) return et . tostring ( testsuites , encoding = "utf-8" )
convert test reports into an xml file
convert test reports into an xml file