-
Notifications
You must be signed in to change notification settings - Fork 11
/
run_tests.py
executable file
·59 lines (48 loc) · 1.69 KB
/
run_tests.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
55
56
57
58
59
#!/usr/bin/env python
from __future__ import unicode_literals
import argparse
import importlib
import os
import sys
import unittest
import tests
if __name__ == "__main__":
# Define arguments
parser = argparse.ArgumentParser(description="Run redis-limpyd tests suite.")
parser.add_argument(
"tests",
nargs="*",
default=None,
help="Tests (module, TestCase or TestCaseMethod) to run. "
"use full path, eg.: `tests.module.Class.test` ; "
"`tests.module.Class` works also ; `tests.module` too!"
)
parser.add_argument(
"-v",
"--verbosity",
type=int,
action="store",
dest="verbosity",
default=2,
help="Verbosity of the runner."
)
args = parser.parse_args()
if args.tests:
# we have names
suite = unittest.TestLoader().loadTestsFromNames(args.tests)
else:
# Run all the tests
suites = []
tests_folder = os.path.dirname(tests.__file__)
for root, dirs, files in os.walk(tests_folder):
for file in files:
if not file.endswith('.py') or file == '__init__.py':
continue
rel_path = os.path.relpath(os.path.join(root, file), start=tests_folder)
module_name = 'tests.' + rel_path.replace('/', '.').replace('\\', '.')[:-3]
module = importlib.import_module(module_name)
suite = unittest.TestLoader().loadTestsFromModule(module)
suites.append(suite)
suite = unittest.TestSuite(suites)
result = unittest.TextTestRunner(verbosity=args.verbosity).run(suite)
sys.exit(not result.wasSuccessful())