chromium/tools/checkteamtags/run_tests

#!/usr/bin/env vpython3
# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Runs all tests in all unit test modules in this directory."""

from __future__ import print_function

import os
import sys
import unittest
import logging


def main():
  if 'full-log' in sys.argv:
    # Configure logging to show line numbers and logging level
    fmt = '%(module)s:%(lineno)d - %(levelname)s: %(message)s'
    logging.basicConfig(level=logging.DEBUG, stream=sys.stdout, format=fmt)
  elif 'no-log' in sys.argv:
    # Only WARN and above are shown, to standard error. (This is the logging
    # module default config, hence we do nothing here)
    pass
  else:
    # Behave as before. Make logging.info mimic print behavior
    fmt = '%(message)s'
    logging.basicConfig(level=logging.INFO, stream=sys.stdout, format=fmt)

  suite = unittest.TestSuite()
  loader = unittest.TestLoader()
  script_dir = os.path.dirname(__file__)
  suite.addTests(loader.discover(start_dir=script_dir, pattern='*_test.py'))

  print('Running unit tests in %s...' % os.path.abspath(script_dir))
  result = unittest.TextTestRunner(verbosity=1).run(suite)
  return 0 if result.wasSuccessful() else 1


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