pythonunittest实现输出HTML、XML测试报告
def run_suite_output_html_report(suite, **args):
'''
python处理xml文件
:param suite: 已组装好的测试套
:param args: 可设置的参数及说明如下:
TEST_OUTPUT_DIR:测试报告输出路径,默认为根⽬录
TEST_OUTPUT_FILE_NAME:测试报告输⼊⽂件名,默认为index.html
:return:
'''
output_dir = ('TEST_OUTPUT_DESCRIPTIONS', load_lib_path.UI_TEST_REPORT_DIR)
single_file = ('TEST_OUTPUT_FILE_NAME', 'index.html')
file_path = os.path.join(output_dir, single_file)
fp = file(file_path, 'wb')
htmlrunner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'uiautotestreport', description=u'ui autotest on chrome')    htmlrunner.run(suite)
XML测试报告:
1、下载如下附件
unittest_xml_reporting-2.1.0-py2.py3-none-any.whl
2、通过PIP进⾏安装: pip install unittest_xml_reporting-2.1.0-py2.py3-none-any.whl
3、添加使⽤⽅法:
def run_suite_output_xml_report(suite, **args):
'''
:param suite: 已组装好的测试套
:param args: 可设置的参数及说明如下:
TEST_OUTPUT_DESCRIPTIONS: 输出描述
TEST_OUTPUT_DIR:测试报告输出路径,默认为根⽬录
TEST_OUTPUT_FILE_NAME:测试报告输⼊⽂件名,默认为hsplatform_l
:return:
'''
descriptions = ('TEST_OUTPUT_DESCRIPTIONS', True)
output_dir = ('TEST_OUTPUT_DESCRIPTIONS', load_lib_path.UI_TEST_REPORT_DIR)
single_file = ('TEST_OUTPUT_FILE_NAME', 'hsplatform_l')
kwargs = dict(verbosity=1, descriptions=descriptions, failfast=False)
if single_file is not None:
file_path = os.path.join(output_dir, single_file)
with open(file_path, 'wb') as xml:
return xmlrunner.XMLTestRunner(output=xml, **kwargs).run(suite)
else :
return xmlrunner.XMLTestRunner(output=output_dir, **kwargs).run(suite)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。