__author__:liubin ''' import unittest from conf import settings from lib import send_email def suite(): test_cases = unittest.defaultTestLoader.\ discover(settings.TEST_PATH,pattern=settings.TEST_PATTERN,top_level_dir=None) # #装载测试用例 # test_cases = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods) # # #使用测试套件并打包测试用例 # test_suit = unittest.TestSuite() # test_suit.addTests(test_cases) return test_cases if __name__ == '__main__': test_result = unittest.TextTestRunner(verbosity=2).run(suite()) print(test_result.testsRun) send_email.send_mail('hello.html')
import unittest from HTMLTestReportCN import HTMLTestRunner from config.config import * from lib.send_email import send_mail logging.info("====================== 测试开始 =======================") suite = unittest.defaultTestLoader.discover(test_path) with open(report_file, 'wb') as f: HTMLTestRunner(stream=f, title="Api Test", description="测试描述", tester="zjk").run(suite) send_mail(report_file) logging.info("======================= 测试结束 =======================")
from lib.send_email import send_mail from run_case import run_case from save_result import save_result ''' 自动化测试执行入口 用例文件为:./testcase/jrkj_testcase.xls 测试结果存放目录:./result ''' _mylogger = get_logger(os.path.basename(__file__)) if __name__ == '__main__': rootPath = os.path.split(os.path.realpath(__file__))[0] _mylogger.info(u'主目录:' + rootPath) casePath = os.path.join(rootPath, 'testcase') resultPath = os.path.join(rootPath, 'result') caseFile = os.path.join(casePath, 'jrkj_testcase.xls') print('caseFile:' + caseFile) run = run_case() if os.path.exists(caseFile): # 打开excel文件读取数据 stepResult, caseResult = run.run_test(caseFile) reportFile = save_result(caseFile, stepResult, caseResult, resultPath) # 邮件发送测试报告 _mylogger.info(reportFile) send_mail(sub=u'jrkj_selenium测试报告', content=u'测试详情见附件', reportFile=reportFile) else: _mylogger.error(u'获取用例文件失败') exit()
import unittest from HTMLTestReportCN import HTMLTestRunner from lib.send_email import send_mail from config.config import * suit=unittest.defaultTestLoader.discover(test_path) with open(report_file,'wb') as f: HTMLTestRunner(stream=f,title="report",description="api test",tester="sun").run(suit) #f.close() send_mail()
# encoding = utf-8 import os import time from MyRunTest import MyRunTest from MyTtestSuite import MyTestSuite from lib.log_config import get_logger from lib.send_email import send_mail _mylogger = get_logger(os.path.basename(__file__)) if __name__ == '__main__': rootDir = os.path.dirname(__file__) testCaseDir = os.path.join(rootDir, 'testCase') resultDir = os.path.join(rootDir, 'result') testNum = time.strftime(('%Y%m%d@%H%M%S')) suite = MyTestSuite().suite(testCaseDir) _mylogger.info(u'测试序列:{}'.format(testNum)) resultFile = os.path.join(resultDir, 'UnittestTextReport{}.html'.format(testNum)) _mylogger.info(u'开始测试') MyRunTest().runTest(suite, resultFile) _mylogger.info(u'测试结束,开始发送测试报告') send_mail('UnitTestReport-{}'.format(testNum), resultFile)