def run_tests(options, args): suite = unittest.TestSuite() if args: if args[0] == 'teardown': test_env.TestEnv().tearDown() exit(0) for arg in args: if hasattr(nocache_tests.TestNocache, arg): suite.addTest(nocache_tests.TestNocache(arg)) elif hasattr(stream_tests.TestStream, arg): suite.addTest(stream_tests.TestStream(arg)) elif hasattr(cache_tests.TestCache, arg) and options.memcache: suite.addTest(cache_tests.TestCache(arg)) elif hasattr(cache_tests.TestWillNotBeCached, arg) and options.memcache: suite.addTest(cache_tests.TestWillNotBeCached(arg)) else: raise Exception(arg, 'not found in tests') else: modules = [nocache_tests, stream_tests, status_tests] if options.memcache: modules.append(cache_tests) for m in modules: suite.addTests(unittest.TestLoader().loadTestsFromModule(m)) env = test_env.TestEnv() try: env.memcache = options.memcache env.setUp() print 'Starting queryservice_test.py' sys.stdout.flush() framework.TestCase.setenv(env) result = unittest.TextTestRunner(verbosity=options.verbose, failfast=True).run(suite) if not result.wasSuccessful(): raise Exception('test failures') finally: if not options.skip_teardown: env.tearDown() if options.keep_logs: print( 'Leaving temporary files behind (--keep-logs), please ' 'clean up before next run: ' + os.environ['VTDATAROOT'])
parser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbose", default=1) parser.add_option("-v", "--verbose", action="store_const", const=2, dest="verbose", default=0) parser.add_option('--skip-teardown', action='store_true') parser.add_option('-k', '--keep-logs', action='store_true', help="Don't delete log files on teardown.") parser.add_option("--mysql-flavor", action="store", type="string") (options, args) = parser.parse_args() utils.options = options logging.getLogger().setLevel(logging.ERROR) set_mysql_flavor(options.mysql_flavor) suite = unittest.TestSuite() if args: if args[0] == 'teardown': test_env.TestEnv(options.env).tearDown() exit(0) for arg in args: if hasattr(nocache_tests.TestNocache, arg): suite.addTest(nocache_tests.TestNocache(arg)) elif hasattr(stream_tests.TestStream, arg): suite.addTest(stream_tests.TestStream(arg)) elif hasattr(cache_tests.TestCache, arg) and options.memcache: suite.addTest(cache_tests.TestCache(arg)) elif hasattr(cache_tests.TestWillNotBeCached, arg) and options.memcache: suite.addTest(cache_tests.TestWillNotBeCached(arg)) else: raise Exception(arg, "not found in tests") else: modules = [nocache_tests, stream_tests, status_tests] if options.memcache: