def main(): """ Invocation order being. 1. Parsing the command line arguments. 2. Parsing the config file to get the configuration details. 3. Invoking the test_list_builder to build the TC run order. 4. Passing the details to the test_runner. """ start = time.time() args = pars_args() try: param_obj = ParamsHandler(args.config_file) except IOError: print("Error: can't find config file or read data.") return # Building the test list and obtaining the TC details. test_cases_tuple = TestListBuilder.create_test_dict( args.test_dir, args.spec_test) test_cases_dict = test_cases_tuple[0] test_cases_component = test_cases_tuple[1] # Creating log dirs. sys.path.insert(1, ".") from common.relog import Logger args.log_dir = f'{args.log_dir}/{datetime.datetime.now()}' Logger.log_dir_creation(args.log_dir, test_cases_component, test_cases_dict) # Pre test run test list builder is modified. test_cases_dict = TestListBuilder.pre_test_run_list_modify(test_cases_dict) # Environment setup. env_obj = environ(param_obj, args.log_dir + "/main.log", args.log_level) env_obj.setup_env() # invoke the test_runner. TestRunner.init(test_cases_dict, param_obj, args.log_dir, args.log_level, args.concur_count) result_queue = TestRunner.run_tests() # Environment cleanup. TBD. total_time = time.time() - start ResultHandler.handle_results(result_queue, args.result_path, total_time, args.excel_sheet)
def main(): """ Invocation order being. 1. Parsing the command line arguments. 2. Parsing the config file to get the configuration details. 3. Invoking the test_list_builder to build the TC run order. 4. Passing the details to the test_runner. """ start = time.time() args = pars_args() if args.show_backtrace: def errer(exc, msg=None): raise exc else: def errer(exc, msg=None): if not msg: msg = "error: {exc}" print(msg.format(exc=exc), file=sys.stderr) sys.exit(1) spinner = Halo(spinner='dots') spinner.start("Starting param handling") try: param_obj = ParamsHandler(args.config_file) except OSError as e: spinner.fail("error in param handling") errer(e, "Error on loading config file: {exc}") spinner.succeed("Param Handling Success.") spinner.start("Building test list") # Building the test list and obtaining the TC details. excluded_result = param_obj.get_excluded_tests() if not excluded_result[1]: spinner.fail("Error in exclude list. Invalid path present") sys.exit(1) excluded_tests = excluded_result[0] spec_test = (args.test_dir.endswith(".py") and args.test_dir.split("/")[-1].startswith("test")) try: TestListBuilder.create_test_dict(args.test_dir, excluded_tests, spec_test) except FileNotFoundError as e: spinner.fail("FileNotFoundError in test list builder") errer(e, "Error: Can't find the file") spinner.succeed("Test List built") spinner.start("Creating log dirs") # Creating log dirs. current_time_rep = str(datetime.datetime.now()) log_dir_current = f"{args.log_dir}/{current_time_rep}" Logger.log_dir_creation(log_dir_current, TestListBuilder.get_test_path_list()) latest = 'latest' tmplink = f"{args.log_dir}/{latest}.{current_time_rep}" os.symlink(current_time_rep, tmplink) os.rename(tmplink, f"{args.log_dir}/{latest}") spinner.succeed("Log dir creation successful.") # Framework Environment datastructure. env_obj = FrameworkEnv() env_obj.init_ds() # Environment setup. env_set = environ(param_obj, env_obj, errer, f"{log_dir_current}/main.log", args.log_level) logger_obj = env_set.get_framework_logger() logger_obj.debug("Running env setup.") env_set.setup_env(args.keep_logs) # invoke the test_runner. logger_obj.debug("Running the test cases.") TestRunner.init(TestListBuilder, param_obj, env_set, log_dir_current, args.log_level, args.concur_count, spec_test) result_queue = TestRunner.run_tests(env_obj) logger_obj.debug("Collected test results queue.") # Environment cleanup. TBD. total_time = time.time() - start # Setup the result if args.excel_sheet is None: handle_results(result_queue, total_time, logger_obj) else: handle_results(result_queue, total_time, logger_obj, args.excel_sheet) logger_obj.debug("Starting env teardown.") env_set.teardown_env()
import os import sys from test_runner import TestRunner __author__ = 'mbugaiov' __copyright__ = "Copyright (C) 2017 Quest, Inc. All rights reserved" #if os.getuid() != 0: # sys.exit("Please run script as root.") ver = sys.version.split()[0] if ver[0:3] != "2.7": sys.exit("Please use python version 2.7") if __name__ == '__main__': test_obj = TestRunner() test_obj.run_tests()