Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ dist_bin_SCRIPTS = \
filters/subunit2gtk \
filters/subunit2junitxml \
filters/subunit2pyunit \
filters/tap2subunit
filters/tap2subunit \
filters/xunit2subunit

TESTS = $(check_PROGRAMS)

Expand Down
76 changes: 76 additions & 0 deletions filters/xunit2subunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python
# subunit: extensions to python unittest to get test results from subprocesses.
# Hewlett Packard Enterprise (c) 2017
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
# project source as Apache-2.0 and BSD. You may not use this file except in
# compliance with one of these two licences.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# license you chose for the specific language governing permissions and
# limitations under that license.
#

"""A filter that reads a xunitXML stream and outputs a subunit stream.
"""

import sys

from subunit.v2 import StreamResultToBytes

STATUS_CODES = frozenset([
'exists',
'fail',
'skip',
'success',
'uxsuccess',
'xfail',
])

try:
import xunitparser
except ImportError:
sys.stderr.write("xunitparser (https://pypi.python.org/pypi/xunitparser)"
"is required for this filter.")
raise

def xunit2subunit(xunitxml_input=sys.stdin, output=sys.stdout):
output = StreamResultToBytes(output)
output.startTestRun()
ts, tr = xunitparser.parse(xunitxml_input)
for tc in ts:
print vars(tc)
test_id = tc.methodname
test_metadata = None
test_status = None
if tc.good:
if tc.result == "skipped":
test_status = "skip"
else:
test_status = "success"
else:
test_status = "fail"
write_test(output, test_id, test_status, test_metadata)
output.stopTestRun()

def write_test(output, test_id, test_status, metadatas):
write_status = output.status
kwargs = {}
if metadatas:
if 'tags' in metadatas:
tags = metadatas['tags']
kwargs['test_tags'] = tags.split(',')
if 'attrs' in metadatas:
test_id = test_id + '[' + metadatas['attrs'] + ']'
kwargs['test_id'] = test_id
write_status(**kwargs)
if test_status in STATUS_CODES:
kwargs['test_status'] = test_status
write_status(**kwargs)

if __name__ == '__main__':
sys.exit(xunit2subunit(sys.stdin, sys.stdout))

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _get_version_from_file(filename, start_of_line, split_marker):
'filters/subunit2junitxml',
'filters/subunit2pyunit',
'filters/tap2subunit',
'filters/xunit2subunit',
],
**extra
)