Skip to content

Refactor run_suite_class #950

@jrotkiewicz

Description

@jrotkiewicz
def run_suite_class(argv=None):
  """Executes tests in the test suite.

  Args:
    argv: A list that is then parsed as CLI args. If None, defaults to sys.argv.
  """
  cli_args = _parse_cli_args(argv)
  suite_class = _find_suite_class()
  if cli_args.list_tests:
    _print_test_names([suite_class])
    sys.exit(0)
  test_configs = config_parser.load_test_config_file(
      cli_args.config, cli_args.test_bed
  )
  config_count = len(test_configs)
  if config_count != 1:
    logging.error('Expect exactly one test config, found %d', config_count)
  config = test_configs[0]
  runner = test_runner.TestRunner(
      log_dir=config.log_path, testbed_name=config.testbed_name
  )
  suite = suite_class(runner, config)
  console_level = logging.DEBUG if cli_args.verbose else logging.INFO
  ok = False
  with runner.mobly_logger(console_level=console_level):
    try:
      suite.setup_suite(config.copy())
      try:
        runner.run()
        ok = runner.results.is_all_pass
        print(ok)
      except signals.TestAbortAll:
        pass
    finally:
      suite.teardown_suite()
  if not ok:
    sys.exit(1)

There are two issues with this function:

  1. it doesn't support --list_tests - it's currently broken

  2. it doesn't work as proposed here:

    Create a subclass of base_suite.BaseSuite and add the individual test

    classes. Using the BaseSuite class allows users to define their own setup
    and teardown steps on the suite level as well as custom config for each test
    class.

    .. code-block:: python

    from mobly import base_suite
    from mobly import suite_runner

    from my.path import MyFooTest
    from my.path import MyBarTest

    class MySuite(base_suite.BaseSuite):

     def setup_suite(self, config):
       # Add a class with default config.
       self.add_test_class(MyFooTest)
       # Add a class with test selection.
       self.add_test_class(MyBarTest,
                           tests=['test_a', 'test_b'])
       # Add the same class again with a custom config and suffix.
       my_config = some_config_logic(config)
       self.add_test_class(MyBarTest,
                           config=my_config,
                           name_suffix='WithCustomConfig')
    

    if name == 'main':
    suite_runner.run_suite_class()

Which would be great if it worked as currently I see no other option to setup test suite with skipping some tests. I would like to use it such that I would be able to skip some predefined tests as in : self.add_test_class(MyBarTest, tests=['test_a', 'test_b'])

Let me know if there is other option for doing that, thank you !

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions