comparison tests/run.py @ 1043:69a9fb45cad5

tests: consolidate all test-loading into the test runner
author Dan Villiom Podlaski Christiansen <dan@cabo.dk>
date Wed, 07 Aug 2013 16:16:49 +0200
parents af84ef787d93
children 3092b3c109a8
comparison
equal deleted inserted replaced
1042:af84ef787d93 1043:69a9fb45cad5
99 99
100 all_tests = tests() 100 all_tests = tests()
101 101
102 args = [i.split('.py')[0].replace('-', '_') for i in args] 102 args = [i.split('.py')[0].replace('-', '_') for i in args]
103 103
104 loader = unittest.TestLoader()
105 suite = unittest.TestSuite()
106
104 if not args: 107 if not args:
105 check = lambda x: options.comprehensive or not comprehensive(x) 108 check = lambda x: options.comprehensive or not comprehensive(x)
106 mods = [m for (n, m) in sorted(all_tests.iteritems()) if check(m)] 109 suite.addTests(loader.loadTestsFromModule(m)
107 suite = [m.suite() for m in mods] 110 for (n, m) in sorted(all_tests.iteritems())
111 if check(m))
108 else: 112 else:
109 suite = []
110 for arg in args: 113 for arg in args:
111 if arg == 'test_util': 114 if arg == 'test_util':
112 continue 115 continue
113 elif arg not in all_tests: 116 elif arg not in all_tests:
114 print >> sys.stderr, 'test module %s not available' % arg 117 print >> sys.stderr, 'test module %s not available' % arg
115 else: 118 else:
116 suite.append(all_tests[arg].suite()) 119 suite.addTest(loader.loadTestsFromModule(all_tests[arg]))
117 120
118 runner = unittest.TextTestRunner(**testargs) 121 runner = unittest.TextTestRunner(**testargs)
119 result = runner.run(unittest.TestSuite(suite)) 122 result = runner.run(suite)
120 if not result.wasSuccessful(): 123 if not result.wasSuccessful():
121 sys.exit(1) 124 sys.exit(1)