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) test_configs = config_parser.load_test_config_file(cli_args.config) 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_class = _find_suite_class() suite = suite_class(runner, config) ok = False with runner.mobly_logger(): 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)
def main(argv=None): """Execute the test class in a test module. This is the default entry point for running a test script file directly. In this case, only one test class in a test script is allowed. To make your test script executable, add the following to your file: .. code-block:: python from mobly import test_runner ... if __name__ == '__main__': test_runner.main() If you want to implement your own cli entry point, you could use function execute_one_test_class(test_class, test_config, test_identifier) Args: argv: A list that is then parsed as cli args. If None, defaults to cli input. """ args = parse_mobly_cli_args(argv) # Find the test class in the test script. test_class = _find_test_class() if args.list_tests: _print_test_names(test_class) sys.exit(0) # Load test config file. test_configs = config_parser.load_test_config_file(args.config[0], args.test_bed) # Parse test specifiers if exist. tests = None if args.tests: tests = args.tests # Execute the test class with configs. ok = True for config in test_configs: runner = TestRunner(log_dir=config.log_path, test_bed_name=config.test_bed_name) with runner.mobly_logger(): runner.add_test_class(config, test_class, tests) try: runner.run() ok = runner.results.is_all_pass and ok except signals.TestAbortAll: pass except: logging.exception('Exception when executing %s.', config.test_bed_name) ok = False if not ok: sys.exit(1)
def run_suite(test_classes, argv=None): """Executes multiple test classes as a suite. This is the default entry point for running a test suite script file directly. Args: test_classes: List of python classes containing Mobly tests. argv: A list that is then parsed as cli args. If None, defaults to cli input. """ args = _parse_cli_args(argv) # Load test config file. test_configs = config_parser.load_test_config_file(args.config) # Check the classes that were passed in for test_class in test_classes: if not issubclass(test_class, base_test.BaseTestClass): logging.error( 'Test class %s does not extend ' 'mobly.base_test.BaseTestClass', test_class) sys.exit(1) # Find the full list of tests to execute selected_tests = compute_selected_tests(test_classes, args.tests) # Execute the suite ok = True for config in test_configs: runner = test_runner.TestRunner(config.log_path, config.testbed_name) with runner.mobly_logger(): for (test_class, tests) in selected_tests.items(): runner.add_test_class(config, test_class, tests) try: runner.run() ok = runner.results.is_all_pass and ok except signals.TestAbortAll: pass except Exception: logging.exception('Exception when executing %s.', config.testbed_name) ok = False if not ok: sys.exit(1)
def main(argv=None): """Execute the test class in a test module. This is the default entry point for running a test script file directly. In this case, only one test class in a test script is allowed. To make your test script executable, add the following to your file: .. code-block:: python from mobly import test_runner ... if __name__ == '__main__': test_runner.main() If you want to implement your own cli entry point, you could use function execute_one_test_class(test_class, test_config, test_identifier) Args: argv: A list that is then parsed as cli args. If None, defaults to cli input. """ # Parse cli args. parser = argparse.ArgumentParser(description='Mobly Test Executable.') group = parser.add_mutually_exclusive_group(required=True) group.add_argument('-c', '--config', nargs=1, type=str, metavar='<PATH>', help='Path to the test configuration file.') group.add_argument( '-l', '--list_tests', action='store_true', help='Print the names of the tests defined in a script without ' 'executing them. If the script ') parser.add_argument('--tests', '--test_case', nargs='+', type=str, metavar='[test_a test_b...]', help='A list of tests in the test class to execute.') parser.add_argument('-tb', '--test_bed', nargs='+', type=str, metavar='[<TEST BED NAME1> <TEST BED NAME2> ...]', help='Specify which test beds to run tests on.') if not argv: argv = sys.argv[1:] args = parser.parse_known_args(argv)[0] # Find the test class in the test script. test_class = _find_test_class() if args.list_tests: _print_test_names(test_class) sys.exit(0) # Load test config file. test_configs = config_parser.load_test_config_file(args.config[0], args.test_bed) # Parse test specifiers if exist. tests = None if args.tests: tests = args.tests # Execute the test class with configs. ok = True for config in test_configs: runner = TestRunner(log_dir=config.log_path, test_bed_name=config.test_bed_name) runner.add_test_class(config, test_class, tests) try: runner.run() ok = runner.results.is_all_pass and ok except signals.TestAbortAll: pass except: logging.exception('Exception when executing %s.', config.test_bed_name) ok = False if not ok: sys.exit(1)
def main(): """Execute the test class in a test module. This is the default entry point for running a test script file directly. In this case, only one test class in a test script is allowed. To make your test script executable, add the following to your file: from mobly import test_runner ... if __name__ == "__main__": test_runner.main() If you want to implement your own cli entry point, you could use function execute_one_test_class(test_class, test_config, test_identifier) """ # Parse cli args. parser = argparse.ArgumentParser(description="Mobly Test Executable.") parser.add_argument('-c', '--config', nargs=1, type=str, required=True, metavar="<PATH>", help="Path to the test configuration file.") parser.add_argument('--test_case', nargs='+', type=str, metavar="[test_a test_b...]", help="A list of test case names in the test script.") parser.add_argument('-tb', '--test_bed', nargs='+', type=str, metavar="[<TEST BED NAME1> <TEST BED NAME2> ...]", help="Specify which test beds to run tests on.") args = parser.parse_args(sys.argv[1:]) # Load test config file. test_configs = config_parser.load_test_config_file(args.config[0], args.test_bed) # Find the test class in the test script. test_class = _find_test_class() test_class_name = test_class.__name__ # Parse test case specifiers if exist. test_case_names = None if args.test_case: test_case_names = args.test_case test_identifier = [(test_class_name, test_case_names)] # Execute the test class with configs. ok = True for config in test_configs: try: result = execute_one_test_class(test_class, config, test_identifier) ok = result and ok except signals.TestAbortAll: pass except: logging.exception("Error occurred when executing test bed %s", config[keys.Config.key_testbed.value]) ok = False if not ok: sys.exit(1)
def run_suite(test_classes, argv=None): """Executes multiple test classes as a suite. This is the default entry point for running a test suite script file directly. Args: test_classes: List of python classes containing Mobly tests. argv: A list that is then parsed as cli args. If None, defaults to cli input. """ # Parse cli args. parser = argparse.ArgumentParser(description='Mobly Suite Executable.') parser.add_argument( '-c', '--config', nargs=1, type=str, required=True, metavar='<PATH>', help='Path to the test configuration file.') parser.add_argument( '--tests', '--test_case', nargs='+', type=str, metavar='[ClassA[.test_a] ClassB[.test_b] ...]', help='A list of test classes and optional tests to execute.') if not argv: argv = sys.argv[1:] args = parser.parse_known_args(argv) # Load test config file. test_configs = config_parser.load_test_config_file(args.config[0]) # Check the classes that were passed in for test_class in test_classes: if not issubclass(test_class, base_test.BaseTestClass): logging.error('Test class %s does not extend ' 'mobly.base_test.BaseTestClass', test_class) sys.exit(1) # Find the full list of tests to execute selected_tests = _compute_selected_tests(test_classes, args.tests) # Execute the suite ok = True for config in test_configs: runner = test_runner.TestRunner(config.log_path, config.test_bed_name) for (test_class, tests) in selected_tests.items(): runner.add_test_class(config, test_class, tests) try: runner.run() ok = runner.results.is_all_pass and ok except signals.TestAbortAll: pass except: logging.exception('Exception when executing %s.', config.test_bed_name) ok = False if not ok: sys.exit(1)
def main(): """This is the default implementation of a cli entry point for ACTS test execution. Or you could implement your own cli entry point using acts.config_parser functions and acts.test_runner.execute_one_test_class. """ parser = argparse.ArgumentParser( description=("Specify tests to run. If nothing specified, " "run all test cases found.")) parser.add_argument('-c', '--config', type=str, required=True, metavar="<PATH>", help="Path to the test configuration file.") parser.add_argument( '-ci', '--campaign_iterations', metavar="<CAMPAIGN_ITERATIONS>", nargs='?', type=int, const=1, default=1, help="Number of times to run the campaign or a group of test cases.") parser.add_argument('-tb', '--testbed', nargs='+', type=str, metavar="[<TEST BED NAME1> <TEST BED NAME2> ...]", help="Specify which test beds to run tests on.") parser.add_argument('-lp', '--logpath', type=str, metavar="<PATH>", help="Root path under which all logs will be placed.") parser.add_argument( '-tp', '--testpaths', nargs='*', type=str, metavar="<PATH> <PATH>", help="One or more non-recursive test class search paths.") group = parser.add_mutually_exclusive_group(required=True) group.add_argument('-tc', '--testclass', nargs='+', type=str, metavar="[TestClass1 TestClass2:test_xxx ...]", help="A list of test classes/cases to run.") group.add_argument( '-tf', '--testfile', nargs=1, type=str, metavar="<PATH>", help=("Path to a file containing a comma delimited list of test " "classes to run.")) parser.add_argument('-ti', '--test_case_iterations', metavar="<TEST_CASE_ITERATIONS>", nargs='?', type=int, help="Number of times to run every test case.") args = parser.parse_args(sys.argv[1:]) test_list = None if args.testfile: test_list = config_parser.parse_test_file(args.testfile[0]) elif args.testclass: test_list = args.testclass if re.search(r'\.ya?ml$', args.config): parsed_configs = mobly_config_parser.load_test_config_file( args.config, args.testbed) else: parsed_configs = config_parser.load_test_config_file( args.config, args.testbed) for test_run_config in parsed_configs: if args.testpaths: tp_key = keys.Config.key_test_paths.value test_run_config.controller_configs[tp_key] = args.testpaths if args.logpath: test_run_config.log_path = args.logpath if args.test_case_iterations: ti_key = keys.Config.key_test_case_iterations.value test_run_config.user_params[ti_key] = args.test_case_iterations # Sets the --testpaths flag to the default test directory if left unset. testpath_key = keys.Config.key_test_paths.value if (testpath_key not in test_run_config.controller_configs or test_run_config.controller_configs[testpath_key] is None): test_run_config.controller_configs[testpath_key] = utils.abs_path( utils.os.path.join(os.path.dirname(__file__), '../../../../acts_tests/tests/')) # TODO(markdr): Find a way to merge this with the validation done in # Mobly's load_test_config_file. if not test_run_config.log_path: raise ActsConfigError("Required key %s missing in test config." % keys.Config.key_log_path.value) test_run_config.log_path = utils.abs_path(test_run_config.log_path) # Prepare args for test runs test_identifiers = config_parser.parse_test_list(test_list) exec_result = _run_tests(parsed_configs, test_identifiers, args.campaign_iterations) if exec_result is False: # return 1 upon test failure. sys.exit(1) sys.exit(0)
def run_suite(test_classes, argv=None): """Execute the test suite in a module. This is the default entry point for running a test suite script file directly. To make your test suite executable, add the following to your file: from mobly import suite_runner from my.test.lib import foo_test from my.test.lib import bar_test ... if __name__ == '__main__': suite_runner.run(foo_test.FooTest, bar_test.BarTest) Args: test_classes: List of python classes containing Mobly tests. argv: A list that is then parsed as cli args. If None, defaults to cli input. """ # Parse cli args. parser = argparse.ArgumentParser(description='Mobly Suite Executable.') parser.add_argument( '-c', '--config', nargs=1, type=str, required=True, metavar='<PATH>', help='Path to the test configuration file.') parser.add_argument( '--test_case', nargs='+', type=str, metavar='[ClassA[.test_a] ClassB[.test_b] ...]', help='A list of test classes and optional test methods to execute.') if not argv: argv = sys.argv[1:] args = parser.parse_args(argv) # Load test config file. test_configs = config_parser.load_test_config_file(args.config[0]) # Check the classes that were passed in for cls in test_classes: if not issubclass(cls, base_test.BaseTestClass): logging.error('Test class %s does not extend ' 'mobly.base_test.BaseTestClass', cls) sys.exit(1) # Choose which tests to run test_identifiers = _compute_test_identifiers(test_classes, args.test_case) # Execute the suite ok = True for config in test_configs: runner = test_runner.TestRunner(config, test_identifiers) try: try: runner.run(test_classes) ok = runner.results.is_all_pass and ok except signals.TestAbortAll: pass except: logging.exception('Exception when executing %s.', runner.test_configs.test_bed_name) ok = False finally: runner.stop() if not ok: sys.exit(1)