def main_hrun(): """ API test: parse command line options and run commands. """ parser = argparse.ArgumentParser( description='HTTP test runner, not just about api test and load test.') parser.add_argument('-V', '--version', dest='version', action='store_true', help="show version") parser.add_argument('testset_paths', nargs='*', help="testset file path") parser.add_argument( '--html-report-name', help= "specify html report name, only effective when generating html report." ) parser.add_argument('--html-report-template', help="specify html report template path.") parser.add_argument('--log-level', default='INFO', help="Specify logging level, default is INFO.") parser.add_argument( '--dot-env-path', help= "Specify .env file path, which is useful for keeping production credentials." ) parser.add_argument( '--failfast', action='store_true', default=False, help="Stop the test run on the first error or failure.") parser.add_argument('--startproject', help="Specify new project name.") args = parser.parse_args() logger.setup_logger(args.log_level) if args.version: logger.color_print("{}".format(__version__), "GREEN") exit(0) dot_env_path = args.dot_env_path or os.path.join(os.getcwd(), ".env") if dot_env_path: load_dot_env_file(dot_env_path) project_name = args.startproject if project_name: project_path = os.path.join(os.getcwd(), project_name) create_scaffold(project_path) exit(0) result = HttpRunner( args.testset_paths, failfast=args.failfast).run(html_report_name=args.html_report_name) print_output(result["output"]) return 0 if result["success"] else 1
def __init__(self, **kwargs): """ initialize test runner @param (dict) kwargs: key-value arguments used to initialize TextTestRunner - resultclass: HtmlTestResult or TextTestResult - failfast: False/True, stop the test run on the first error or failure. - dot_env_path: .env file path """ dot_env_path = kwargs.pop("dot_env_path", None) load_dot_env_file(dot_env_path) kwargs.setdefault("resultclass", HtmlTestResult) self.runner = unittest.TextTestRunner(**kwargs)
def main_hrun(): """ API test: parse command line options and run commands. """ parser = argparse.ArgumentParser(description=__description__) parser.add_argument('-V', '--version', dest='version', action='store_true', help="show version") parser.add_argument('testset_paths', nargs='*', help="testset file path") parser.add_argument('--no-html-report', action='store_true', default=False, help="do not generate html report.") parser.add_argument( '--html-report-name', help= "specify html report name, only effective when generating html report." ) parser.add_argument('--html-report-template', help="specify html report template path.") parser.add_argument('--log-level', default='INFO', help="Specify logging level, default is INFO.") parser.add_argument('--log-file', help="Write logs to specified file path.") parser.add_argument( '--dot-env-path', help= "Specify .env file path, which is useful for keeping production credentials." ) parser.add_argument( '--failfast', action='store_true', default=False, help="Stop the test run on the first error or failure.") parser.add_argument('--startproject', help="Specify new project name.") parser.add_argument('--validate', nargs='*', help="Validate JSON testset format.") parser.add_argument('--prettify', nargs='*', help="Prettify JSON testset format.") args = parser.parse_args() logger.setup_logger(args.log_level, args.log_file) if is_py2: logger.log_warning(get_python2_retire_msg()) if args.version: logger.color_print("{}".format(__version__), "GREEN") exit(0) if args.validate: validate_json_file(args.validate) exit(0) if args.prettify: prettify_json_file(args.prettify) exit(0) dot_env_path = args.dot_env_path or os.path.join(os.getcwd(), ".env") if dot_env_path: load_dot_env_file(dot_env_path) project_name = args.startproject if project_name: project_path = os.path.join(os.getcwd(), project_name) create_scaffold(project_path) exit(0) runner = HttpRunner(failfast=args.failfast).run(args.testset_paths) if not args.no_html_report: runner.gen_html_report(html_report_name=args.html_report_name, html_report_template=args.html_report_template) summary = runner.summary print_output(summary["output"]) return 0 if summary["success"] else 1
def __init__(self, **kwargs): dot_env_path = kwargs.pop("dot_env_path", None) load_dot_env_file(dot_env_path) kwargs.setdefault("resultclass", HtmlTestResult) self.runner = unittest.TextTestRunner(**kwargs)