예제 #1
0
def set_exec_usefile(_file, sheet):
    if os.path.isfile(_file):  # dir or file
        datas_path_file = os.path.join(datas_path, _file)
        logger.info(
            f"---datas_path:{datas_path}-------{datas_path_file}--------------"
        )
        ReadWriteConfFile().set_option('exec', 'exec_file_path',
                                       datas_path_file)
        if sheet:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name',
                                           str(sheet))
        else:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '1'
    elif os.path.isdir(_file):  # dir or file
        ReadWriteConfFile().set_option('exec', 'exec_file_path', _file)
        if sheet:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name',
                                           str(sheet))
        else:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '2'
    else:  # error file or floder
        logger.info(f"---datas_path:{datas_path}---------------------")
        ReadWriteConfFile().set_option('exec', 'exec_file_path', datas_path)
        ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '3'
예제 #2
0
def set_exec_usefile(file, sheet):
    if os.path.isfile(file):  # dir or file
        datas_path_file = os.path.join(datas_path, file)
        ReadWriteConfFile().set_option('exec', 'exec_file_path', datas_path_file)
        if sheet:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', str(sheet))
        else:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '1'
    elif os.path.isdir(file):  # dir or file
        ReadWriteConfFile().set_option('exec', 'exec_file_path', file)
        if sheet:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', str(sheet))
        else:
            ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '2'
    else:  # error file or floder
        ReadWriteConfFile().set_option('exec', 'exec_file_path', datas_path)
        ReadWriteConfFile().set_option('exec', 'exec_sheet_name', '')
        return '3'
예제 #3
0
import logging, os
import logging.handlers
from Common.setting import REPORT_DIR, LOG_DIR
from Common.handle_config import ReadWriteConfFile

get_logdir = ReadWriteConfFile().get_option('report_dir', 'report_dir_folder')
num = ReadWriteConfFile().get_option('report_file', 'file_num')
log_dir = os.path.join(REPORT_DIR, get_logdir)
log_file_format = os.path.join(log_dir, f'{get_logdir}_{num}.log')

log_file = os.path.join(LOG_DIR, 'Test.log')

class HandleLogger:
    """
    定义一个日志处理类
    """
    def __init__(self):
        self.case_logger = logging.getLogger('LOG')  # 创建一个日志收集器
        fmt = '%(asctime)s %(name)s %(levelname)s %(filename)s-%(lineno)d line:%(message)s'
        self.case_logger.setLevel(logging.DEBUG)  # 指定日志收集器的日志等级

        sizefilehandler = logging.handlers.RotatingFileHandler(log_file, mode='a', maxBytes=1024*1024*5, backupCount=10,
                                                               encoding='utf-8', delay=False)
        console_handle = logging.StreamHandler()  # 定义一个控制台输出渠道
        file_handle2 = logging.FileHandler(log_file, encoding='utf-8')  # 定义一个文件输出渠道
        file_handle = logging.FileHandler(log_file_format, encoding='utf-8')

        console_handle.setLevel(logging.ERROR)  # 设置控制台输出渠道的日志级别为ERROR
        file_handle.setLevel(logging.INFO)  # 设置文件输出渠道的日志级别为INFO
        file_handle2.setLevel(logging.INFO)
예제 #4
0
def set_exec_ini(section, option, value):
    ReadWriteConfFile().add_section(section)
    ReadWriteConfFile().set_option(section, option, value)
예제 #5
0
# -*- coding: utf-8 -*-
import pytest, os, time, subprocess, sys, re
import requests
from Common.handle_logger import logger
from Common.handle_config import ReadWriteConfFile
from Common.utils import start_time_format, use_time, report_date_folder
from Common.handle_file import file_zip_path, file_del, file_copy, file_and_folder_copy, current_folder_file_copy
from Common.setting import BASE_DIR, REPORT_DIR, REPORT_CURRENT_DIR
from Common.handle_logger import logger

_session = None
_date = report_date_folder()
datas_path = os.path.join(BASE_DIR, "TestCases")
sheet = ReadWriteConfFile().get_option('exec', 'exec_sheet_name')
file_name = "test_apidata.xlsx"
execfile = ReadWriteConfFile().get_option('exec', 'exec_file_path')


def pytest_addoption(parser):
    """add --report"""
    parser.addoption(
        "--report",
        action="store",
        default=_date,  # 'Report_allure'
        help="current report directory")


@pytest.fixture(scope="session", autouse=True)
def report(request):
    """get command line parameters
    :param request: --report
예제 #6
0
import pytest
import allure
import os, sys
from Common.handle_logger import logger
from Apikeywords.apiKeyWords import Http
from Common.handle_excel import excel_to_case, load_excel, excel_to_save, Handle_excel
from Common.handle_config import ReadWriteConfFile
from Common.setting import REPORT_DIR, BASE_DIR, CASES_DIR

execfile = ReadWriteConfFile().get_option('exec', 'exec_file_path')
execst = ReadWriteConfFile().get_option('exec', 'st')
execsheet = ReadWriteConfFile().get_option('exec', 'exec_sheet_name')

report_excel = ReadWriteConfFile().get_option('report_dir',
                                              'report_dir_folder')
tmp_excel_path = os.path.join(REPORT_DIR, report_excel)
num = ReadWriteConfFile().get_option('report_file', 'file_num')

execfile = os.path.dirname(__file__)
apidata = excel_to_case(execfile, execst, execsheet)


class TestAPI():
    @pytest.mark.parametrize('data', apidata)
    def test_all_api(self, requests_session, data):

        http = Http(requests_session)

        allure.dynamic.feature(
            f'{self.__class__.__name__}.{sys.__loader__.__name__}')
        allure.dynamic.story(
예제 #7
0
import pytest, os, subprocess
from Common.handle_config import ReadWriteConfFile
from conftest import set_exec_ini
from Common.setting import BASE_DIR


file_path = r"D:/desk20201127/ksgit/TestCases/" #test_apidata.xlsx
# datas_path = os.path.join(BASE_DIR, "Datas")


set_exec_ini('exec', 'exec_file_path', file_path)
set_exec_ini('exec', 'exec_sheet_name', '')

pytest.main([])  # '--report','re2021'
dir = ReadWriteConfFile().get_option('report_dir', 'report_dir_folder')
cmd = f'allure generate ./temp -o ./Report/{dir}/allure/ --clean'
# report_dir_format = ReadWriteConfFile().set_option('report_dir', 'report_dir_folder', '')
os.system(cmd)

# execfile = os.path.join(os.path.dirname(__file__),'a.py') #D:/desk20201127/ksgit\a.py
# print(execfile)