forked from cms-sw/pkgtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runTests
executable file
·43 lines (39 loc) · 1.32 KB
/
runTests
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
#!/usr/bin/env python
from optparse import OptionParser
from imp import load_module, find_module
from os.path import join, abspath
import sys
from traceback import print_exc
def outputToFile (f):
olderr, oldout = (sys.stderr, sys.stdout)
sys.stderr = sys.stdout = f
return (oldout, olderr)
def outputToSTD (old):
sys.stderr, sys.stdout = old
if __name__ == "__main__":
parser = OptionParser ()
parser.add_option ("-v", "--verbose", dest="verbose", default=False, action="store_true")
parser.add_option ("-o", "--log-output", dest="logfile", default="log.txt")
opts, args = parser.parse_args ()
baseDir = abspath (__file__).rsplit ("/", 1)[0]
sys.path.append (baseDir)
testDir = join (baseDir, "tests")
log = open (opts.logfile, "w")
for testcase in args:
print "Running test `%s`" % testcase
try:
if not opts.verbose:
old = outputToFile (log)
__import__ ("tests.test_" + testcase)
if not opts.verbose:
outputToSTD (old)
result = "OK"
except:
if not opts.verbose:
outputToSTD (old)
if opts.verbose:
print_exc ()
result="ERROR"
else:
result="ERROR"
print "Test result: %s" % result