import os
import sys
import unittest
import inspect
import pychecker2
import glob

modules = []
exit_status = 0

def test(modules):
    global exit_status
    for m in modules:
        s = unittest.defaultTestLoader.loadTestsFromName(m)
        result = unittest.TextTestRunner().run(s)
        if not result.wasSuccessful():
            exit_status = 1

def _make_coverage_dirs(root):

    coverage_dir = os.path.join(root, 'coverage', root[1:], 'utest')
    if not os.path.exists(coverage_dir):
        os.makedirs(coverage_dir)

def _modules(root):
    modules = []
    for fname in glob.glob(os.path.join(root, 'utest', '*.py')):
        fname = os.path.split(fname)[1] # remove path
        module = 'pychecker2.utest.' + os.path.splitext(fname)[0]
        if not module.endswith('_'):    # ignore __init__
            modules.append(module)
    return modules

def main():
    global modules
    root = os.path.dirname(inspect.getsourcefile(pychecker2))
    _make_coverage_dirs(root)
    modules = _modules(root)

    try:
        import trace
        ignore = trace.Ignore(dirs = [sys.prefix, sys.exec_prefix])
        coverage = trace.Coverage(ignore)
        trace.run(coverage.trace, 'test(modules)')
        trace.create_results_log(coverage.results(), 'coverage')
    except Exception, detail:
        print 'Error: %s, not tracing' % `detail`
        test(modules)


if __name__ == '__main__':
    main()
    sys.exit(exit_status)

@@ -115,23 +115,16 @@
 ef test(
-modules
 ):%0A    g
@@ -1036,16 +1036,121 @@
 t trace%0A
+    except Exception, detail:%0A        print 'Error: %25s, not tracing' %25 %60detail%60%0A        test()%0A    else:%0A
         
@@ -1291,23 +1291,16 @@
 , 'test(
-modules
 )')%0A    
@@ -1368,106 +1368,12 @@
     
-except Exception, detail:%0A        print 'Error: %25s, not tracing' %25 %60detail%60%0A        test(modules)%0A
+    
 %0A%0Aif

add some better debugging dumps