Workaround to remove tests without name from xml report files
We use some tools to upload xml reports to Polarion in downstream, which fail when some testcase entries are generated without 'name' This seems to be a pytest issue The intention of this patch is to remove those entries as a workaround until the real issue is fixed in pytest Change-Id: I82d750c24976ad6c0e4be1aa2bfd4865f96aeb42
This commit is contained in:
parent
329bcd9e7b
commit
95fb5b5c95
@ -0,0 +1,40 @@
|
||||
# Copyright 2022 Red Hat
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import argparse
|
||||
from xml.etree import ElementTree
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Remove testcases with no name '
|
||||
'from the provided xml report file')
|
||||
parser.add_argument('--xmlfile', type=str, required=True,
|
||||
help='XML report file path')
|
||||
args = parser.parse_args()
|
||||
|
||||
report_tree = ElementTree.parse(args.xmlfile)
|
||||
report_root = report_tree.getroot()
|
||||
testsuite = report_root[0]
|
||||
new_testsuite = ElementTree.Element('testsuite')
|
||||
for testcase in testsuite:
|
||||
if 'name' in testcase.attrib:
|
||||
new_testsuite.append(testcase)
|
||||
new_testsuite.attrib = testsuite.attrib
|
||||
report_root[0] = new_testsuite
|
||||
report_tree.write(
|
||||
args.xmlfile, encoding="utf-8", xml_declaration=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -39,6 +39,14 @@
|
||||
json_query("[?stat.exists].stat.path") }}
|
||||
|
||||
|
||||
- name: "[workaround] remove test entries with no 'name' from the xml report files"
|
||||
script:
|
||||
cmd: "remove_tests_withoutname_fromxmlreport.py --xmlfile {{ item }}"
|
||||
executable: python3
|
||||
when: item is regex('.*\.xml')
|
||||
loop: '{{ report_files }}'
|
||||
|
||||
|
||||
- name: "collect report files to local directory '{{ collect_dir }}'"
|
||||
synchronize:
|
||||
dest: '{{ collect_dir }}/{{ item | basename }}'
|
||||
|
Loading…
Reference in New Issue
Block a user