def __test_copy_logs_deprecated(self, ztestsuite, localhost_log_file, fetch_logs_flag = True): """ base test method containing common code called by public test methods for testing execution of copy of logs based on deprecated function signatures """ #first set things up #create a temp dir for logs import tempfile runtime.reset_all() #create the log file on "remote" which is actually localhost with open( localhost_log_file, 'wb') as f: f.write("This is a log") runner = TestRunner(ztestsuite=ztestsuite, should_fetch_logs=fetch_logs_flag) logs_dir = tempfile.mkdtemp() runner.set_logs_dir(logs_dir) try: runner.run() #no logs specified on default, so should not have any files if fetch_logs_flag: self.assertEqual( os.listdir(logs_dir), ['ztestsuite.unittest-' + os.path.basename(localhost_log_file)]) else: self.assertEqual( os.listdir(logs_dir),[]) except: raise finally: #cleanup shutil.rmtree( logs_dir)
def test_full_run(self): """ Tests a full run """ test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_with_naarad.py") test_runner = TestRunner(test_file, ["test0", "test1", "test2"], {}) test_runner.run()
def test_full_run_parallel(self): """ Tests a full run with parallel tests """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_with_naarad_run_tests_in_parallel.py") test_runner = TestRunner(test_file, ["test0", "test1", "test2"], {}, reporter_type='junit_reporter') test_runner.run()
def test_full_run_with_skip(self): """ Tests failing setup for one test and having it skip """ test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_first_setup.py") test_runner = TestRunner(test_file, None, {"max_failures_per_suite_before_abort": -1}) test_runner.run()
def test_full_run_junit(self): """ Tests a full run """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_junit_reports.py") test_runner = TestRunner(test_file, ["test0", "test1", "test2"], {}) test_runner.run()
def test_full_run(self): """ Tests a full run """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_with_naarad.py") test_runner = TestRunner(test_file, ["test0", "test1", "test2"], {}) test_runner.run()
def test_full_run_with_skip(self): """ Tests failing setup for one test and having it skip """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_first_setup.py") test_runner = TestRunner(test_file, None, {"max_failures_per_suite_before_abort": -1}, reporter_type='junit_reporter') test_runner.run()
def test_full_run_with_skip_and_stop_all_config(self): """ Tests failing consectutive setup_suites and skipping the rest of the configurations. """ test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_setup_suite.py") test_runner = TestRunner(test_file, None, {"max_suite_failures_before_abort": 0}) test_runner.run()
def test_full_run_with_skip_and_stop_one_config(self): """ Tests failing consecutive setups and having the entire execution of a configuration stop. """ test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_all_setup.py") test_runner = TestRunner(test_file, None, {"max_failures_per_suite_before_abort": 0}) test_runner.run()
def test_full_run_with_skip_and_stop_one_config(self): """ Tests failing consecutive setups and having the entire execution of a configuration stop. """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_all_setup.py") test_runner = TestRunner(test_file, None, {"max_failures_per_suite_before_abort": 0}, reporter_type='junit_reporter') test_runner.run()
def test_full_run_with_skip_and_stop_all_config(self): """ Tests failing consectutive setup_suites and skipping the rest of the configurations. """ runtime.reset_collector() test_file = os.path.join(self.FILE_LOCATION, "samples/sample_test_fail_setup_suite.py") test_runner = TestRunner(test_file, None, {"max_suite_failures_before_abort": 0}, reporter_type='junit_reporter') test_runner.run()
def call_main(args): # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) raise # Set up logging. setup_logging(runtime.get_output_dir(), args.log_level, args.console_level) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) utils.check_testfile_dir_structure(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: logger.error(str(e)) print("Error in processing command line arguments:\n {0}".format( traceback.format_exc())) raise runtime.set_machines(machines) if args.user is not None: user = args.user else: user = getpass.getuser() if args.nopassword: password = "" else: password = getpass.getpass() runtime.set_user(user, password) try: testmodule = utils.load_module(args.testfile) ztestsuites = [ getattr(testmodule, attr) for attr in dir(testmodule) if isinstance(getattr(testmodule, attr), ZTestSuite) ] if len( ztestsuites ) > 0: #TODO(jehrlich) intelligently handle multiple test suites test_runner = TestRunner(ztestsuite=ztestsuites[0], testlist=args.test_list, config_overrides=config_overrides) else: test_runner = TestRunner(args.testfile, args.test_list, config_overrides) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) raise ValueError(e.message) test_runner.run() logger.info("Exiting zopkio") return test_runner.success_count(), test_runner.fail_count()
def test_copy_logs_empty_default(self): #first set things up runtime.reset_all() ztestsuite = SampleTestSuite() runtime.set_active_config(Config("unittestconfig",{})) runner = TestRunner(ztestsuite=ztestsuite) #create a temp dir for logs import tempfile logs_dir = tempfile.mkdtemp() runner.set_logs_dir(logs_dir) runner._copy_logs() try: #no logs specified on default, so should not have any files self.assertTrue( os.listdir(logs_dir) == []) except: raise finally: #cleanup shutil.rmtree( logs_dir)
def __test_copy_logs_deprecated(self, ztestsuite, localhost_log_file, fetch_logs_flag=True): """ base test method containing common code called by public test methods for testing execution of copy of logs based on deprecated function signatures """ #first set things up #create a temp dir for logs import tempfile runtime.reset_all() #create the log file on "remote" which is actually localhost with open(localhost_log_file, 'wb') as f: f.write("This is a log") runner = TestRunner(ztestsuite=ztestsuite, should_fetch_logs=fetch_logs_flag) logs_dir = tempfile.mkdtemp() runner.set_logs_dir(logs_dir) try: runner.run() #no logs specified on default, so should not have any files if fetch_logs_flag: self.assertEqual(os.listdir(logs_dir), [ 'ztestsuite.unittest-' + os.path.basename(localhost_log_file) ]) else: self.assertEqual(os.listdir(logs_dir), []) except: raise finally: #cleanup shutil.rmtree(logs_dir)
def call_main(args): # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) raise # Set up logging. setup_logging(runtime.get_output_dir(), args.log_level, args.console_level) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) utils.check_testfile_dir_structure(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: logger.error(str(e)) print("Error in processing command line arguments:\n {0}".format(traceback.format_exc())) raise runtime.set_machines(machines) if args.user is not None: user = args.user else: user = getpass.getuser() if args.nopassword: password = "" else: password = getpass.getpass() runtime.set_user(user, password) try: testmodule = utils.load_module(args.testfile) ztestsuites = [getattr(testmodule, attr) for attr in dir(testmodule) if isinstance(getattr(testmodule, attr), ZTestSuite)] if len(ztestsuites) > 0: #TODO(jehrlich) intelligently handle multiple test suites test_runner = TestRunner(ztestsuite=ztestsuites[0], testlist=args.test_list, config_overrides=config_overrides) else: test_runner = TestRunner(args.testfile, args.test_list, config_overrides) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) raise ValueError(e.message) test_runner.run() logger.info("Exiting zopkio") return test_runner.success_count(), test_runner.fail_count()
def test_copy_logs_empty_default(self): #first set things up runtime.reset_all() ztestsuite = SampleTestSuite() runtime.set_active_config(Config("unittestconfig", {})) runner = TestRunner(ztestsuite=ztestsuite) #create a temp dir for logs import tempfile logs_dir = tempfile.mkdtemp() runner.set_logs_dir(logs_dir) runner._copy_logs() try: #no logs specified on default, so should not have any files self.assertTrue(os.listdir(logs_dir) == []) except: raise finally: #cleanup shutil.rmtree(logs_dir)
def main(): """ Parse command line arguments and then run the test suite """ parser = argparse.ArgumentParser( description='A distributed test framework') parser.add_argument( 'testfile', help='The file that is used to determine the test suite run') parser.add_argument( '--test-only', nargs='*', dest='test_list', help='run only the named tests to help debug broken tests') parser.add_argument( '--machine-list', nargs='*', dest='machine_list', help='''mapping of logical host names to physical names allowing the same test suite to run on different hardware, each argument is a pair of logical name and physical name separated by a =''') parser.add_argument( '--config-overrides', nargs='*', dest='config_overrides', help= '''config overrides at execution time, each argument is a config with its value separated by a =. This has the highest priority of all configs''') parser.add_argument( '-d', '--output-dir', dest='output_dir', help='''Directory to write output files and logs. Defaults to the current directory.''') parser.add_argument("--log-level", dest="log_level", help="Log level (default INFO)", default="INFO") parser.add_argument("--console-log-level", dest="console_level", help="Console Log level (default ERROR)", default="ERROR") parser.add_argument("--nopassword", action='store_true', dest="nopassword", help="Disable password prompt") parser.add_argument( "--user", dest="user", help="user to run the test as (defaults to current user)") parser.add_argument( "--reporter", dest="reporter", help="reporter type that will be use to generate report)") args = parser.parse_args() # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) sys.exit(1) # Set up logging. setup_logging(runtime.get_output_dir(), args.log_level, args.console_level) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) utils.check_testfile_dir_structure(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: logger.error(str(e)) print("Error in processing command line arguments:\n {0}".format( traceback.format_exc())) sys.exit(1) runtime.set_machines(machines) if args.user is not None: user = args.user else: user = getpass.getuser() if args.nopassword: password = "" else: password = getpass.getpass() runtime.set_user(user, password) try: testmodule = utils.load_module(args.testfile) ztestsuites = [ getattr(testmodule, attr) for attr in dir(testmodule) if isinstance(getattr(testmodule, attr), ZTestSuite) ] # reporter_type = runtime.get_active_config('zopkio_reporter') reporter_type = None if args.reporter is not None: reporter_type = args.reporter if len( ztestsuites ) > 0: #TODO(jehrlich) intelligently handle multiple test suites test_runner = TestRunner(ztestsuite=ztestsuites[0], testlist=args.test_list, config_overrides=config_overrides, reporter_type=reporter_type) else: test_runner = TestRunner(args.testfile, args.test_list, config_overrides, reporter_type=reporter_type) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) sys.exit(1) print "CONFIG_OVERRIDE: %s" % (config_overrides, ) test_runner.run() logger.info("Exiting zopkio")
def main(): """ Parse command line arguments and then run the test suite """ parser = argparse.ArgumentParser( description='A distributed test framework') parser.add_argument( 'testfile', help='The file that is used to determine the test suite run') parser.add_argument( '--test-only', nargs='*', dest='test_list', help='run only the named tests to help debug broken tests') parser.add_argument( '--machine-list', nargs='*', dest='machine_list', help='''mapping of logical host names to physical names allowing the same test suite to run on different hardware, each argument is a pair of logical name and physical name separated by a =''') parser.add_argument( '--config-overrides', nargs='*', dest='config_overrides', help= '''config overrides at execution time, each argument is a config with its value separated by a =. This has the highest priority of all configs''') parser.add_argument( '-d', '--output-dir', dest='output_dir', help='''Directory to write output files and logs. Defaults to the current directory.''') parser.add_argument("--log-level", dest="log_level", help="Log level (default INFO)", default="INFO") parser.add_argument("--console-log-level", dest="console_level", help="Console Log level (default ERROR)", default="ERROR") parser.add_argument("--nopassword", action='store_true', dest="nopassword", help="Disable password prompt") args = parser.parse_args() # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) sys.exit(1) # Set up logging. runtime.set_init_time(time.time()) setup_logging(runtime.get_output_dir(), args.log_level, args.console_level) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: print("Error in processing command line arguments:\n %s".format( traceback.format_exc())) sys.exit(1) runtime.set_machines(machines) user = getpass.getuser() if args.nopassword: password = "" else: password = getpass.getpass() runtime.set_user(user, password) try: test_runner = TestRunner(args.testfile, args.test_list, config_overrides) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) sys.exit(1) test_runner.run() logger.info("Exiting zopkio")
def main(): """ Parse command line arguments and then run the test suite """ parser = argparse.ArgumentParser(description='A distributed test framework') parser.add_argument('testfile', help='The file that is used to determine the test suite run') parser.add_argument('--test-only', nargs='*', dest='test_list', help='run only the named tests to help debug broken tests') parser.add_argument('--machine-list', nargs='*', dest='machine_list', help='''mapping of logical host names to physical names allowing the same test suite to run on different hardware, each argument is a pair of logical name and physical name separated by a =''') parser.add_argument('--config-overrides', nargs='*', dest='config_overrides', help='''config overrides at execution time, each argument is a config with its value separated by a =. This has the highest priority of all configs''') parser.add_argument('-d', '--output-dir', dest='output_dir', help='''Directory to write output files and logs. Defaults to the current directory.''') args = parser.parse_args() # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) sys.exit(1) # Set up logging. runtime.set_init_time(time.time()) setup_logging(runtime.get_output_dir()) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: print("Error in processing command line arguments:\n %s" % traceback.format_exc()) sys.exit(1) runtime.set_machines(machines) user = getpass.getuser() password = getpass.getpass() runtime.set_user(user, password) try: test_runner = TestRunner(args.testfile, args.test_list, config_overrides) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) sys.exit(1) test_runner.run() logger.info("Exiting zopkio")
def main(): """ Parse command line arguments and then run the test suite """ parser = argparse.ArgumentParser(description='A distributed test framework') parser.add_argument('testfile', help='The file that is used to determine the test suite run') parser.add_argument('--test-only', nargs='*', dest='test_list', help='run only the named tests to help debug broken tests') parser.add_argument('--machine-list', nargs='*', dest='machine_list', help='''mapping of logical host names to physical names allowing the same test suite to run on different hardware, each argument is a pair of logical name and physical name separated by a =''') parser.add_argument('--config-overrides', nargs='*', dest='config_overrides', help='''config overrides at execution time, each argument is a config with its value separated by a =. This has the highest priority of all configs''') parser.add_argument('-d', '--output-dir', dest='output_dir', help='''Directory to write output files and logs. Defaults to the current directory.''') parser.add_argument("--log-level", dest="log_level", help="Log level (default INFO)", default="INFO") parser.add_argument("--console-log-level", dest="console_level", help="Console Log level (default ERROR)", default="ERROR") parser.add_argument("--nopassword", action='store_true', dest="nopassword", help="Disable password prompt") parser.add_argument("--user", dest="user", help="user to run the test as (defaults to current user)") args = parser.parse_args() # Get output directory. try: if args.output_dir is not None: runtime.set_output_dir(args.output_dir) except ValueError as e: print str(e) sys.exit(1) # Set up logging. setup_logging(runtime.get_output_dir(), args.log_level, args.console_level) logger = logging.getLogger("zopkio") logger.info("Starting zopkio") try: utils.check_file_with_exception(args.testfile) utils.check_testfile_dir_structure(args.testfile) machines = utils.make_machine_mapping(args.machine_list) config_overrides = utils.parse_config_list(args.config_overrides) except ValueError as e: logger.error(str(e)) print("Error in processing command line arguments:\n {0}".format(traceback.format_exc())) sys.exit(1) runtime.set_machines(machines) if args.user is not None: user = args.user else: user = getpass.getuser() if args.nopassword: password = "" else: password = getpass.getpass() runtime.set_user(user, password) try: testmodule = utils.load_module(args.testfile) ztestsuites = [getattr(testmodule, attr) for attr in dir(testmodule) if isinstance(getattr(testmodule, attr), ZTestSuite)] if len(ztestsuites) > 0: #TODO(jehrlich) intelligently handle multiple test suites test_runner = TestRunner(ztestsuite=ztestsuites[0], testlist=args.test_list, config_overrides=config_overrides) else: test_runner = TestRunner(args.testfile, args.test_list, config_overrides) except BaseException as e: print("Error setting up testrunner:\n%s" % traceback.format_exc()) sys.exit(1) test_runner.run() logger.info("Exiting zopkio")