-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_tests.py
executable file
·44 lines (31 loc) · 1.03 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
#!/usr/bin/env python
import imp
import sys
import inspect
from glob import glob
import re
import unittest
# Main suite, which holds all TestCases
main_suite = unittest.TestSuite()
# Loop over all files in the test directory
for pyfile in glob("test/*.py"):
# Extract the module name
m = re.match("test/(.*)\\.py", pyfile)
if not m:
continue
test_case_name = m.group(1)
# Import module
test_module = imp.load_source("%s" % test_case_name, pyfile)
# Loop over items in the module
for name, item in vars(test_module).items():
# Skip items, which are not TestCase
if not (inspect.isclass(item) and issubclass(item, unittest.TestCase)):
continue
# Build suite from this TestCase and add it to the main suite
single_suite = unittest.TestLoader().loadTestsFromTestCase(item)
main_suite.addTest(single_suite)
# Run Tests
result = unittest.TextTestRunner(verbosity=3).run(main_suite)
# Check result
if not result.wasSuccessful():
sys.exit(1)