1#!/usr/bin/python 2# 3# Copyright 2018 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Main entry point for all of acloud's unittest.""" 17 18import logging 19import pkgutil 20import sys 21import unittest 22 23 24# Needed to silence oauth2client. 25# This is a workaround to get rid of below warning message: 26# 'No handlers could be found for logger "oauth2client.contrib.multistore_file' 27# TODO(b/112803893): Remove this code once bug is fixed. 28OAUTH2_LOGGER = logging.getLogger('oauth2client.contrib.multistore_file') 29OAUTH2_LOGGER.setLevel(logging.CRITICAL) 30OAUTH2_LOGGER.addHandler(logging.FileHandler("/dev/null")) 31 32# Setup logging to be silent so unittests can pass through TF. 33ACLOUD_LOGGER = "acloud" 34logger = logging.getLogger(ACLOUD_LOGGER) 35logger.setLevel(logging.CRITICAL) 36logger.addHandler(logging.FileHandler("/dev/null")) 37 38 39def main(): 40 """Main unittest entry. 41 42 Args: 43 argv: A list of system arguments. (unused) 44 45 Returns: 46 0 if success. None-zero if fails. 47 """ 48 test_modules = [ 49 mod.name 50 for mod in pkgutil.walk_packages() 51 if mod.name.startswith('acloud') and mod.name.endswith('_test') 52 ] 53 54 loader = unittest.defaultTestLoader 55 test_suite = loader.loadTestsFromNames(test_modules) 56 runner = unittest.TextTestRunner(verbosity=2) 57 result = runner.run(test_suite) 58 sys.exit(not result.wasSuccessful()) 59 60 61if __name__ == '__main__': 62 main() 63