TestSuite.run源码修改
摘抄自:https://blog.csdn.net/hqzxsc2006/article/details/50349664
def run(self,result, debug=False):
failcount= 1 # 失败总运行次数
class_num= 1
topLevel= False
if getattr(result,'_testRunEntered',False) is False:
result._testRunEntered= topLevel= True
for testin self:
case_num= 1
if result.shouldStop:
break
success_flag= True
while success_flag:
if _isnotsuite(test):
self._tearDownPreviousClass(test,result)
self._handleModuleFixture(test,result)
self._handleClassSetUp(test,result)
result._previousTestClass= test.__class__
if (getattr(test.__class__,'_classSetupFailed',False) or
getattr(result,'_moduleSetUpFailed',False)):
if class_num> failcount:
success_flag= False
else:
time.sleep(5)
result._previousTestClass= None
print('类%s第%s次重新初始化执行' % (test.__class__, class_num))
class_num+= 1
continue
if not debug:
test(result)
else:
test.debug()
if result.result[-1][0] == 1 or result.result[-1][0] == 2: # 结果为fail和err用例判断
if case_num> failcount:
success_flag= False
else:
print('用例%s第%s次重新执行' % (test, case_num))
case_num+= 1
else:
success_flag= False
if topLevel:
self._tearDownPreviousClass(None,result)
self._handleModuleTearDown(result)
result._testRunEntered= False
return result
获取所有测试用例
屏幕唤醒我们可以用adb shell 命令执行 (在python 使用system模块执行cmd命令)
tip:需要先设置取消图形解锁
import os
com='adb shell input keyevent 26 && adb shell input swipe 500 700 500 50'
os.system(com)
HTMLTestRunner 执行并生成报告
test_report_dir= 'F:\\result' #存放报告地址
now= time.strftime('%Y-%m-%d_%H_%M_%S_') #生成运行时间点
filename= test_report_dir+ '\\' + now+ 'result.html' #生成报告文件名
fp= open(filename,'wb') #打开文件
alltest= creatSuite() #获取用例
runner= HTMLTestRunner(stream=fp,title=u'测试报告',description=u'用例执行情况:')
runner.run(alltest) #运行用例
fp.close() #关闭文件
new_report= new_file(test_report_dir) #取最新测试报告
send_email(new_report) #发送邮件,发送最新测试报告html
(send_email 方法已封装 可参考http://www.cnblogs.com/yufeihlf/p/5752146.html)