Suggest providing a "test" command, not the old self-test attribute
[0release.git] / tests / testall.py
blob0de81cfa482162217325bd4c510fea039ccacb23
1 #!/usr/bin/env python
2 import unittest, os, sys
3 try:
4 import coverage
5 coverage.use_cache(False)
6 coverage.erase()
7 coverage.start()
8 except ImportError:
9 coverage = None
11 my_dir = os.path.dirname(sys.argv[0])
12 if not my_dir:
13 my_dir = os.getcwd()
15 testLoader = unittest.TestLoader()
17 if len(sys.argv) > 1:
18 alltests = testLoader.loadTestsFromNames(sys.argv[1:])
19 else:
20 alltests = unittest.TestSuite()
22 suite_names = [f[:-3] for f in os.listdir(my_dir)
23 if f.startswith('test') and f.endswith('.py')]
24 suite_names.remove('testall')
25 suite_names.sort()
27 for name in suite_names:
28 m = __import__(name, globals(), locals(), [])
29 t = testLoader.loadTestsFromModule(m)
30 alltests.addTest(t)
32 a = unittest.TextTestRunner(verbosity=2).run(alltests)
34 if coverage:
35 coverage.stop()
36 else:
37 print "Coverage module not found. Skipping coverage report."
39 print "\nResult", a
40 if not a.wasSuccessful():
41 sys.exit(1)
43 if coverage:
44 all_sources = []
45 def incl(d):
46 for x in os.listdir(d):
47 if x.endswith('.py'):
48 all_sources.append(os.path.join(d, x))
49 incl('..')
50 coverage.report(all_sources + ['../0publish'])