forked from vmalloc/pyforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests
executable file
·55 lines (48 loc) · 1.5 KB
/
run_tests
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
#! /usr/bin/python
import os
import sys
try:
import unittest2 as unittest
except ImportError:
import unittest
loader = unittest.TestLoader()
def main():
suite = _build_suite()
runner = _build_runner()
runner.run(suite)
def _build_suite():
returned = unittest.TestSuite()
for module in _iterate_modules():
for test_case in _iterate_module_test_cases(module):
returned.addTest(test_case)
return returned
def _iterate_modules():
orig_sys_path = sys.path
sys.path.insert(0, "tests")
try:
for path, dirnames, filenames in os.walk("tests"):
path = os.path.relpath(path, "tests")
for filename in filenames:
if not filename.endswith(".py"):
continue
if path != '.':
filename = os.path.join(path, filename)
module = __import__(filename[:-3].replace("/", "."))
yield module
finally:
sys.path = orig_sys_path
def _iterate_module_test_cases(module):
for name, var in vars(module).iteritems():
if name.startswith("_"):
continue
if not isinstance(var, type) or not issubclass(var, unittest.TestCase):
continue
if var.__module__ != module.__name__:
continue
for test_case in loader.loadTestsFromTestCase(var):
yield test_case
def _build_runner():
returned = unittest.TextTestRunner()
return returned
if __name__ == '__main__':
main()