python中unittest单元测试框架-加载测试用例、运行测试用例、生成测试报告-通过discover加载某个文件夹下的所有用例


import os
import unittest
import HTMLTestRunnerNew

# 1、初始化testloader
testloader = unittest.TestLoader()

# 2、查找测试用例,加载
dir = os.path.dirname(os.path.abspath(__file__))
case_dir = os.path.join(dir, 'test_cases')

suite = testloader.discover(case_dir)


# 创建存放测试报告的文件夹-report
report_path = os.path.join(dir, 'report')
if not os.path.exists(report_path):
    os.mkdir(report_path)

file_path = os.path.join(report_path, 'test_result.html')

with open(file_path, "wb+") as f:
    # 初始化运行期, 是以普通文本生成测试报告 TextTestRunner
    runner = HTMLTestRunnerNew.HTMLTestRunner(stream=f, title='API测试报告', description='执行用例详情', tester='奔奔')
    # 运行测试用例
    runner.run(suite)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM