Python用于预定义的Junit XML

时间:2018-03-21 05:52:30

标签: python junit

我必须开发一个python脚本,以下列格式生成Junit XML

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite name="Scenario3" time="0.015">
        <testcase name="testcase09"/>
        <testcase name="testcase10">
            <skipped />
        </testcase>
        <testcase name="testcase11">
            <failure type="AssertionFailure">
            <![CDATA[ Failed 1 times. ]]>
            </failure>
       </testcase>
    </testsuite>
</testsuites>

我做了一个基本的python代码,但无法标记如上所示

from junit_xml import TestSuite, TestCase
test_cases = []
for result in results:
    tc_name, tc_result = result
    if tc_result == "PASS":
        test_cases.append(TestCase(tc_name))
        ts = TestSuite("S", test_cases)
print(TestSuite.to_xml_string([ts]))enter code here

请对上述

提出建议

1 个答案:

答案 0 :(得分:0)

这可以使用Decode完成        来自junit_xml import TestSuite,TestCase,Decode

从上面我们可以将测试用例标记为失败/跳过等