Beispiel #1
0
def run_test():
    """
    定义运行测试的函数
    :return:
    """

    # 数据初始化
    db = DB()
    with open('datas.ymal', 'r') as fr:
        datas = yaml.load(fr)
        db.init_data(datas)

    test_dir = '.'
    report_dir = "./reports/"

    # 执行测试
    discovery = unittest.defaultTestLoader.discover(
        test_dir,
        pattern="test_django_restful.py",
    )
    now = time.strftime("%Y-%m-%d_%H_%M_%S")
    report_path = report_dir + now + "test_report.html"
    with open(report_path, 'wb') as fw:
        runner = BSTestRunner(stream=fw,
                              title="Django_api_test",
                              description="Django_restful_API_Test_rport")
        logging.info("=========Start API Test==========")

        runner.run(discovery)
        logging.info("=========Finish API Test==========")
Beispiel #2
0
# __author__ = "yw"
import unittest
from BSTestRunner import BSTestRunner
import time, yaml
from mysql_action import DB
import logging.config

CON_LOG = 'log.conf'
logging.config.fileConfig(CON_LOG)
logging = logging.getLogger()

# 数据初始化操作
db = DB()
f = open('datas.yaml', 'r')
datas = yaml.load(f)
db.init_data(datas)

# 指定测试用例和测试报告的路径
test_dir = '.'
report_dir = './reports'

#加载测试用例
discover = unittest.defaultTestLoader.discover(
    test_dir, pattern='test_django_restful.py')

# 定义报告的文件格式
# now = time.strftime("%Y-%m-%d %H_%M_%S")
now = time.strftime("%Y%m%d%H%M%S")
report_name = report_dir + '/' + now + 'test_report.html'

# 运行用例并生成测试报告