直接上代碼。
# -*- coding: utf-8 -*-import timeimport osimport os.pathimport reimport unittestimport HTMLTestRunnerimport shutilshutil.copyfile("setting.ini","../setting.ini")casepaths = []def createsuite(casepath): testunit = unittest.TestSuite() #discover方法定義 discover = unittest.defaultTestLoader.discover( casepath, pattern = 'case*.py', top_level_dir= casepath ) for test_suite in discover: for test_case in test_suite: testunit.addTest(test_case) print testunit return testunitfor parent,dirnames,filenames in os.walk('.'): for filename in filenames: #print "parent is:" + parent #print "filename is:" + filename path=os.path.join(parent,filename) #正則判斷是否為測試用例 match = re.match('case', filename) if match: print u"獲取測試用例目錄:%s"%parent casepaths.append(parent) break #定義報(bào)告存放目錄,支持相對路徑now = time.strftime("%Y-%m-%M-%H-%M-%S",time.localtime(time.time()))filename = now+'report.html'fp = file(filename,'wb')runner = HTMLTestRunner.HTMLTestRunner(stream = fp,title = u'自動(dòng)化測試報(bào)告',description = u'用例執(zhí)行情況') for casepath in casepaths: print u"正在執(zhí)行 %s目錄下的測試用例"%casepath alltestnames = createsuite(casepath) runner.run(alltestnames) print u"執(zhí)行 %s目錄下的測試用例完成"%casepathprint u"完成所有測試用例執(zhí)行任務(wù)"以上這篇python selenium執(zhí)行所有測試用例并生成報(bào)告的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長站。
新聞熱點(diǎn)
疑難解答
圖片精選