def testrun_gen(tests, filename, config, collectonly=True): """Generates content of the XML file used for test run import.""" prop_dict = { 'testrun-template-id': xunit.get('testrun_template_id'), 'testrun-title': config.getoption('xmls_testrun_title') or xunit.get('testrun_title'), 'testrun-id': config.getoption('xmls_testrun_id') or xunit.get('testrun_id'), 'project-id': xunit['project_id'], 'group-id': xunit.get('group_id'), 'dry-run': xunit.get('dry_run', False), 'testrun-status-id': xunit['testrun_status_id'], 'lookup-method': xunit['lookup_method'] } testsuites = etree.Element("testsuites") testsuite = etree.Element("testsuite") properties = etree.Element("properties") property_resp = etree.Element('property', name='polarion-response-{}'.format( xunit['response']['id']), value=xunit['response']['value']) properties.append(property_resp) for prop_name, prop_value in prop_dict.items(): if prop_value is None: continue prop_el = etree.Element('property', name="polarion-{}".format(prop_name), value=str(prop_value)) properties.append(prop_el) testsuites.append(properties) testsuites.append(testsuite) no_tests = 0 results_count = {'passed': 0, 'skipped': 0, 'failure': 0, 'error': 0} for data in tests: no_tests += 1 if collectonly: testsuite.append( testresult_record(data['name'], data.get('params'))) results_count['skipped'] += 1 else: testsuite.append( testresult_record(data['name'], data.get('params'), result=data.get('result'))) results_count[data['result']] += 1 testsuite.attrib['tests'] = str(no_tests) testsuite.attrib['failures'] = str(results_count['failure']) testsuite.attrib['skipped'] = str(results_count['skipped']) testsuite.attrib['errors'] = str(results_count['error']) testsuite.attrib['name'] = "cfme-tests" xml = etree.ElementTree(testsuites) xml.write(filename, pretty_print=True)
def testrun_gen(tests, filename, config, collectonly=True): """Generates content of the XML file used for test run import.""" prop_dict = { 'testrun-template-id': xunit.get('testrun_template_id'), 'testrun-title': config.getoption('xmls_testrun_title') or xunit.get('testrun_title'), 'testrun-id': config.getoption('xmls_testrun_id') or xunit.get('testrun_id'), 'project-id': xunit['project_id'], 'group-id': xunit.get('group_id'), 'dry-run': xunit.get('dry_run', False), 'testrun-status-id': xunit['testrun_status_id'], 'lookup-method': xunit['lookup_method'] } testsuites = etree.Element("testsuites") testsuite = etree.Element("testsuite") properties = etree.Element("properties") property_resp = etree.Element( 'property', name='polarion-response-{}'.format( xunit['response']['id']), value=xunit['response']['value']) properties.append(property_resp) for prop_name, prop_value in prop_dict.items(): if prop_value is None: continue prop_el = etree.Element( 'property', name="polarion-{}".format(prop_name), value=str(prop_value)) properties.append(prop_el) testsuites.append(properties) testsuites.append(testsuite) no_tests = 0 results_count = { 'passed': 0, 'skipped': 0, 'failure': 0, 'error': 0 } for data in tests: no_tests += 1 if collectonly: testsuite.append(testresult_record(data['name'], data.get('params'))) results_count['skipped'] += 1 else: testsuite.append(testresult_record( data['name'], data.get('params'), result=data.get('result'))) results_count[data['result']] += 1 testsuite.attrib['tests'] = str(no_tests) testsuite.attrib['failures'] = str(results_count['failure']) testsuite.attrib['skipped'] = str(results_count['skipped']) testsuite.attrib['errors'] = str(results_count['error']) testsuite.attrib['name'] = "cfme-tests" xml = etree.ElementTree(testsuites) xml.write(filename, pretty_print=True)
def testcases_gen(tests, filename): """Generates content of the XML file used for test cases import.""" testcases = etree.Element("testcases") testcases.attrib['project-id'] = xunit['project_id'] response_properties = etree.Element("response-properties") response_property = etree.Element( "response-property", name=xunit['response']['id'], value=xunit['response']['value']) response_properties.append(response_property) properties = etree.Element("properties") lookup = etree.Element("property", name="lookup-method", value="custom") properties.append(lookup) dry_run = etree.Element("property", name="dry-run", value=str(xunit.get("dry_run", "false"))) properties.append(dry_run) testcases.append(response_properties) testcases.append(properties) for data in tests: testcases.append(testcase_record(**data)) xml = etree.ElementTree(testcases) xml.write(filename, pretty_print=True)