예제 #1
0
def run_all():
    nowTime = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
    reportName = 'unittest_' + str(nowTime)
    reportFileName = reportName + '.html'
    test_folder = config.unittestPath

    if platform.system() == 'Windows':
        reportNameFull = config.reportPath + '\\' + reportFileName
    else:
        reportNameFull = config.reportPath + '/' + reportFileName

    start_time = datetime.datetime.now()
    pytest.main([
        test_folder,
        '--html=%s' % reportNameFull, '-o log_cli=true -o log_cli_level=INFO'
    ])
    end_time = datetime.datetime.now()

    # 插入数据库
    test_unittest_manage.test_unittest_manage().new_unittest_case(
        reportName, start_time, end_time, reportFileName)
예제 #2
0
def run_all():
    # 通过配置项,读取报告的存储路径 reportPath
    if platform.system() == 'Windows':
        reportPath = autotestconfig.reportPathWin
        currentPath = autotestconfig.unittestPathWin
    else:
        reportPath = autotestconfig.reportPathLinux
        currentPath = autotestconfig.unittestPathLinux
    # 获取当前路径
    # currentPath = os.getcwd()
    log.log().logger.info('reportPath is %s: ' % reportPath)
    log.log().logger.info('currentPath is %s: ' % currentPath)
    nowTime = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
    reportName = 'unittest_' + str(nowTime)
    reportFileName = reportName + '.html'

    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    # 执行当前  test 路径下的所以  test 类
    suite.addTests(loader.discover(currentPath))

    # 测试用例执行器
    runner = HTMLReport.TestRunner(
        report_file_name=reportName,  # 报告文件名,默认“test”
        output_path=reportPath,  # 保存文件夹名,默认“report”
        verbosity=3,  # 控制台输出详细程度,默认 2
        title='测试报告',  # 报告标题,默认“测试报告”
        description='无测试描述',  # 报告描述,默认“无测试描述”
        thread_count=1,  # 并发线程数量(无序执行测试),默认数量 1
        sequential_execution=True  # 是否按照套件添加(addTests)顺序执行,
        # 会等待一个addTests执行完成,再执行下一个,默认 False
    )
    # 执行测试用例套件
    start_time = datetime.datetime.now()
    runner.run(suite)
    end_time = datetime.datetime.now()

    #插入数据库
    test_unittest_manage.test_unittest_manage().new_unittest_case(
        reportName, start_time, end_time, reportFileName)
예제 #3
0
파일: utils.py 프로젝트: testervic/AutoTest
def view_unitest_result():
    info = request.values
    log.log().logger.info('info : %s' % info)
    id = viewutil.getInfoAttribute(info, 'id')
    # from app import test_unittest_manage
    data = test_unittest_manage.test_unittest_manage().show_unittest_records(
        ['id'], [id], [], 100)
    if len(data):
        filename = data[0]['file_name']
        return render_template("util/unittest_detail.html",
                               file_name='/view_unitest_results?id=' + id)
    else:
        return render_template("util/unittest_records.html")
예제 #4
0
def test_unittest_result():
    if request.method == 'POST':
        log.log().logger.info('post')
        result = jsonify({'code': 500, 'msg': 'should be get!'})
        return result
    else:
        info = request.values
        log.log().logger.info('info :  %s' %info)
        name = viewutil.getInfoAttribute(info, 'name')
        limit = info.get('limit', 10)  # 每页显示的条数
        offset = info.get('offset', 0)  # 分片数,(页码-1)*limit,它表示一段数据的起点
        data= test_unittest_manage.test_unittest_manage().show_unittest_records(['name'], [name], [], 100)
        data1 = jsonify({'total': len(data), 'rows': data[int(offset):int(offset) + int(limit)]})
        log.log().logger.info('data1: %s' %data1)
        return data1, {'Content-Type': 'application/json'}