HTMLTestRunner run.py的写法
程序员文章站
2022-03-03 09:01:17
...
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
test_dir='./test_case_dir'
report_dir='./reports'
#执行文件夹下的所以测试用例
# discover=unittest.defaultTestLoader.discover(start_dir=test_dir)
#执行指定的测试类用例
discover=unittest.defaultTestLoader.discover(test_dir,pattern='test_api.py')
# #执行匹配条件的测试用例
# discover=unittest.defaultTestLoader.discover(test_dir,pattern='test*.py')
now=time.strftime('%Y-%m-%d %H_%M_%S')
report_name=report_dir+'/'+now+'test_report.html'
with open(report_name,'wb') as f:
runner=HTMLTestRunner(stream=f,title='Weather API Test Report',description='China city weather report')
runner.run(discover)