-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrunUnitTest.py
54 lines (47 loc) · 1.8 KB
/
runUnitTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: UTF-8 -*-
import unittest,sys
from BeautifulReport import BeautifulReport as bf
from myunittest import datadriven
from common import config
from common.mysql import Mysql
from common import logger
# 运行的相对路径
path = '.'
# 用例路径
casepath = ''
resultpath = ''
if __name__ == '__main__':
# unittest.main()
# suite = unittest.TestSuite()
# suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(testWeb))
# suite = unittest.defaultTestLoader.discover(".", pattern="baidu.py", top_level_dir=None)
# # 生成执行用例的对象
# runner = bf(suite)
# runner.report(filename='./test.html', description='这个描述参数是必填的')
try:
casepath = sys.argv[1]
except:
casepath = ''
# 为空,则使用默认的
if casepath == '':
casepath = path + '/lib/HTTP.xls'
resultpath = path + '/lib/结果-HTTP.xls'
else:
# 如果是绝对路径,就使用绝对路径
if casepath.find(':') >= 0:
# 获取用例文件名
resultpath = path + '/lib/结果-' + casepath[casepath.rfind('\\') + 1:]
else:
logger.error('非法用例路径')
config.get_config(path + '/lib/conf.properties')
# logger.info(config.config)
mysql = Mysql()
mysql.init_mysql(path + '/lib/userinfo.sql')
title = datadriven.getparams(casepath,resultpath)
# unittest.main()
# suite = unittest.TestSuite()
# suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(baidu))
suite = unittest.defaultTestLoader.discover("./myunittest/", pattern="WebTest.py", top_level_dir=None)
# 生成执行用例的对象
runner = bf(suite)
runner.report(filename='./test.html', description=title)