Beispiel #1
0
import unittest

from libs import HTMLTestRunnerNew

from config.config import CASE_DIR, ENVIRONMENT, REPORT_DIR, CONFIG_PATH
from common.CreatePath import ModelsClass
from common.ParseConfig import ParseConfigFile

pc = ParseConfigFile()


def tc_suite():
    """测试套件"""
    discover = unittest.defaultTestLoader.discover(CASE_DIR, "test_*.py")
    return discover


if __name__ == "__main__":
    report_dir = ModelsClass.create_dir(REPORT_DIR)
    report_file_name = ModelsClass.file_name("html")

    with open(report_dir + "/" + report_file_name, "wb") as f:
        runner = HTMLTestRunnerNew.HTMLTestRunner(stream=f,
                                                  description=ENVIRONMENT,
                                                  title=pc.getConfValue(
                                                      CONFIG_PATH, "Project",
                                                      "PRO_NAME"),
                                                  tester="Anton Zhang",
                                                  verbosity=2)
        runner.run(tc_suite())
Beispiel #2
0
from common.ParseConfig import do_config
from common.SendEmail import SendMailWithReport


def tc_suite():
    """测试套件"""
    suite = unittest.TestSuite()
    discover = unittest.defaultTestLoader.discover(CASE_DIR, 'test_*.py')
    suite.addTest(discover)
    return suite


# TODO: Optimizing code
# TODO: add log
if __name__ == '__main__':
    ModelsClass.create_dir(LOG_DIR)
    report_dir = ModelsClass.create_dir(REPORT_DIR)
    report_file_name = ModelsClass.file_name('html')
    report_path = report_dir + '/' + report_file_name
    # 第一种测试报告
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner.HTMLTestReportCN(
            stream=f,
            description=ENVIRONMENT,
            title=do_config('Project', 'Name'),
            tester=do_config('Project', 'Tester'),
            verbosity=2)
        runner.run(tc_suite())
        SendMailWithReport.send_mail(
            do_config("Email_Config", "server"),
            do_config("Email_Config", "from_user"),
Beispiel #3
0
This module stores the file directories and files needed by the project
"""
"""
All dirs of the project
"""
PRO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.dirname(os.path.abspath(__file__))
CASE_DIR = os.path.join(PRO_DIR, 'cases')
DATA_DIR = os.path.join(PRO_DIR, 'data')
CONFIG_PATH = os.path.join(CONFIG_DIR, 'config.ini')
DATA_PATH = os.path.join(DATA_DIR, 'testcases.xlsx')
USER_PATH = os.path.join(CONFIG_DIR, 'userinfo.ini')
"""
log & Report name and dir
"""
LOG_NAME = ModelsClass.file_name('log')
LOG_DIR = os.path.join(PRO_DIR, 'log')  #ModelsClass.create_dir('log')
CREATE_LOG_DIR = ModelsClass.create_dir(LOG_DIR)
LOG_PATH = os.path.join(LOG_DIR, LOG_NAME)
REPORT_DIR = os.path.join(PRO_DIR, 'report')
"""
Test environment info
"""
ENVIRONMENT = \
    "Windows Version:" + \
    platform.system() + \
    platform.version() + \
    platform.release() + \
    "Python Version" + \
    platform.python_build()[0]
Beispiel #4
0
            datefmt='%a, %d %b %Y %H:%M:%S')
        file_handler.setFormatter(formatter)

    @staticmethod
    def __close_handler(file_handler):
        """关闭handler"""
        file_handler.close()

    @property
    def logger(self):
        """构造收集器,返回logger"""
        file_handler = self.__ini_handler()
        self.__set_handler(file_handler)
        self.__set_formatter(file_handler)
        self.__close_handler(file_handler)
        return self.__logger


log_name = ModelsClass.file_name('log')
log = Log(__name__, LOG_DIR + '/' + log_name)
logger = log.logger

if __name__ == '__main__':
    log = Log(__name__, 'file.log')
    logger = log.logger
    logger.debug('I am a debug message')
    logger.info('I am a info message')
    logger.warning('I am a warning message')
    logger.error('I am a error message')
    logger.critical('I am a critical message')