3 # Author: David Goodger
4 # Contact: goodger@users.sourceforge.net
7 # Copyright: This module has been placed in the public domain.
10 All modules named 'test_*.py' in the current directory, and recursively in
11 subdirectories (packages) called 'test_*', are loaded and test suites within
16 # Start point for actual elapsed time, including imports
17 # and setup outside of unittest.
26 """Write to a file and a stream (default: stdout) simultaneously."""
28 def __init__(self
, filename
, stream
=sys
.__stdout
__):
29 self
.file = open(filename
, 'w')
32 def write(self
, string
):
33 self
.stream
.write(string
)
34 self
.file.write(string
)
43 suitestr
= repr(suite
).replace('=[<', '=[\n<').replace(', ', ',\n')
46 for line
in suitestr
.splitlines():
47 output
.append(' ' * indent
+ line
)
51 if line
[-5:] == ']>]>,':
53 elif line
[-3:] == ']>,':
55 return '\n'.join(output
)
58 # must redirect stderr *before* first import of unittest
59 sys
.stdout
= sys
.stderr
= Tee('alltests.out')
61 import package_unittest
63 path
, script
= os
.path
.split(sys
.argv
[0])
64 suite
= package_unittest
.loadTestModules(path
, 'test_', packages
=1)
65 package_unittest
.main(suite
)
66 #if package_unittest.verbosity > 1:
67 # print >>sys.stderr, pformat(suite) # check the test suite
70 print 'Elapsed time: %.3f seconds' % (finish
- start
)