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
|
#!/usr/bin/python -tt
# Load and runs the test from the utest subdirectory
# your unittests should append ".." to their path to
# find the files relative to this directory
import unittest
from glob import glob
import os
import sys
prefix = ''
append_path = False
if __name__ != '__main__':
prefix = __name__[:-5]
append_path = True
def suite():
# If we are not called directly, we have
# to append this path to sys.path so our
# subtests will find their files
this_dir = os.path.dirname(__file__)
if append_path:
sys.path.append(this_dir)
suite = unittest.TestSuite()
l = unittest.TestLoader()
dname = os.path.dirname(__file__)
for f in glob('%s/utest/*.py' % dname):
if os.path.basename(f) == '__init__.py':
continue
modname = '%sutest.%s' % (prefix, os.path.basename(f)[:-3])
# Load tests
tests = l.loadTestsFromName(modname)
suite.addTests(tests)
if append_path:
sys.path.remove(this_dir)
return suite
def main():
tsuite = suite()
runner = unittest.TextTestRunner()
runner.run(tsuite)
return unittest.TestResult()
if __name__ == '__main__':
main()
|