-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
48 lines (36 loc) · 1.16 KB
/
runtests.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@author: george wang
@datetime: 2019-07-22
@file: runtests.py
@contact: [email protected]
@desc: 跑测试用例
"""
import logging
import sys
import unittest
from argparse import ArgumentParser
from ammonia import tests
logger = logging.getLogger(__name__)
def collect_tests():
suite = unittest.TestSuite()
module_suite = unittest.TestLoader().loadTestsFromModule(tests)
suite.addTest(module_suite)
return suite
def run_tests(suite, verbosity=1):
runner = unittest.TextTestRunner(verbosity=verbosity)
results = runner.run(suite)
return results.failfast, results.errors
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('-v', '--verbosity', dest="verbosity", type=int, default=1, help="输出错误详细程度")
args = parser.parse_args(args=sys.argv[1:])
tests = collect_tests()
failures, errors = run_tests(tests, args.verbosity)
if failures:
logger.info('-' * 20 + 'failures' + '-' * 20)
logging.info(failures)
if errors:
logging.info('-' * 20 + 'errors' + '-' * 20)
logging.info(errors)