#执行用例
caselist = config.caselist
for i in range(0,len(caselist)):
reportname = caselist[i][2:]
now = config.now
screenshotpath = config.screenshotpath
def creatsuitel():
os.mkdir(screenshotpath)
testunit=suite.Suit()
#discover 方法定义
discover=unittest.defaultTestLoader.discover(caselist[i],pattern ='test_*.py',top_level_dir=None)
#discover 方法筛选出来的用例,循环添加到测试套件中
for test_suite in discover:
for test_case in test_suite:
print(test_case)
testunit.addTests(test_case)
return testunit
alltestnames = creatsuitel()
report = config.reportpaht + reportname + now + '.html'
fp = open(report, 'wb')
runner =HTMLTestRunner.HTMLTestRunner(stream=fp,title=u'自动化测试报告',description=u'用例执行情况:')
#执行测试用例
runner.run(alltestnames)
fp.close()
#发送结果邮件,先压缩再发送
# zip.zip_compression(config.reportpaht, config.reportpaht + "report.zip")
# SentEmail.sentemail(config.reportpaht + "report.zip")