예제 #1
0
 def SetUpProcess(cls):
   """ Set up testing logic before running the test case.
   This is guaranteed to be called only once for all the tests before the test
   suite runs.
   """
   cls._finder_options = browser_test_context.GetCopy().finder_options
   cls.platform = None
   cls.browser = None
   cls._browser_to_create = None
   cls._browser_options = None
def LoadAllTestsInModule(module):
    """ Load all tests & generated browser tests in a given module.

  This is supposed to be invoke in load_tests() method of your test modules that
  use browser_test_runner framework to discover & generate the tests to be
  picked up by the test runner. Here is the example of how your test module
  should looks like:

  ################## my_awesome_browser_tests.py  ################
  import sys

  from telemetry.testing import serially_executed_browser_test_case
  ...

  class TestSimpleBrowser(
      serially_executed_browser_test_case.SeriallyExecutedBrowserTestCase):
  ...
  ...

  def load_tests(loader, tests, pattern):
    return serially_executed_browser_test_case.LoadAllTestsInModule(
        sys.modules[__name__])
  #################################################################

  Args:
    module: the module which contains test cases classes.

  Returns:
    an instance of unittest.TestSuite, which contains all the tests & generated
    test cases to be run.
  """
    suite = unittest.TestSuite()
    test_context = browser_test_context.GetCopy()
    if not test_context:
        return suite
    for _, obj in inspect.getmembers(module):
        if (inspect.isclass(obj)
                and issubclass(obj, SeriallyExecutedBrowserTestCase)):
            # We bail out early if this class doesn't match the targeted
            # test_class in test_context to avoid calling GenerateTestCases
            # for tests that we don't intend to run. This is to avoid possible errors
            # in GenerateTestCases as the test class may define custom options in
            # the finder_options object, and hence would raise error if they can't
            # find their custom options in finder_options object.
            if test_context.test_class != obj:
                continue
            for test in GenerateTestCases(
                    test_class=obj,
                    finder_options=test_context.finder_options):
                if test.id() in test_context.test_case_ids_to_run:
                    suite.addTest(test)
    return suite
예제 #3
0
  def SetUpProcess(cls):
    """ Set up testing logic before running the test case.
    This is guaranteed to be called only once for all the tests before the test
    suite runs.
    """
    finder_options = browser_test_context.GetCopy().finder_options
    cls._finder_options = finder_options

    # Set up logging based on the verbosity passed from the parent to
    # the child process.
    if finder_options.verbosity >= 2:
      logging.getLogger().setLevel(logging.DEBUG)
    elif finder_options.verbosity:
      logging.getLogger().setLevel(logging.INFO)
    else:
      logging.getLogger().setLevel(logging.WARNING)
    logging.basicConfig(format=DEFAULT_LOG_FORMAT)

    cls.platform = None
    cls.browser = None
    cls._browser_to_create = None
    cls._browser_options = None
예제 #4
0
 def TearDownProcess(cls):
     actual_finder_options = browser_test_context.GetCopy().finder_options
     test_state_json_path = actual_finder_options.test_state_json_path
     with open(test_state_json_path, 'w') as f:
         json.dump(cls._test_state, f)
     super(_BaseSampleIntegrationTest, cls).TearDownProcess()