()
return 0
API test: parse command line options and run commands.
API test: parse command line options and run commands.
API test : parse command line options and run commands .
def main_hrun():
    """ API test: parse command line options and run commands.
    """
    import argparse
    from httprunner import logger
    from httprunner.__about__ import __description__, __version__
    from httprunner.api import HttpRunner
    from httprunner.compat import is_py2
    from httprunner.utils import (create_scaffold, get_python2_retire_msg,
                                prettify_json_file, validate_json_file)

    parser = argparse.ArgumentParser(description=__description__)
    parser.add_argument(
        '-V', '--version', dest='version', action='store_true',
        help="show version")
    parser.add_argument(
        'testcase_paths', nargs='*',
        help="testcase file 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 sensitive data.")
    parser.add_argument(
        '--report-template',
        help="specify report template path.")
    parser.add_argument(
        '--report-dir',
        help="specify report save directory.")
    parser.add_argument(
        '--failfast', action='store_true', default=False,
        help="Stop the test run on the first error or failure.")
    parser.add_argument(
        '--save-tests', action='store_true', default=False,
        help="Save loaded tests and parsed tests to JSON file.")
    parser.add_argument(
        '--startproject',
        help="Specify new project name.")
    parser.add_argument(
        '--validate', nargs='*',
        help="Validate JSON testcase format.")
    parser.add_argument(
        '--prettify', nargs='*',
        help="Prettify JSON testcase 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)

    project_name = args.startproject
    if project_name:
        create_scaffold(project_name)
        exit(0)

    runner = HttpRunner(
        failfast=args.failfast,
        save_tests=args.save_tests,
        report_template=args.report_template,
        report_dir=args.report_dir
    )
    try:
        for path in args.testcase_paths:
            runner.run(path, dot_env_path=args.dot_env_path)
    except Exception:
        logger.log_error("!!!!!!!!!! exception stage: {} !!!!!!!!!!".format(runner.exception_stage))
        raise

    return 0
def main_hrun ( ) : import argparse from httprunner import logger from httprunner . __about__ import __description__ , __version__ from httprunner . api import HttpRunner from httprunner . compat import is_py2 from httprunner . utils import ( create_scaffold , get_python2_retire_msg , prettify_json_file , validate_json_file ) parser = argparse . ArgumentParser ( description = __description__ ) parser . add_argument ( '-V' , '--version' , dest = 'version' , action = 'store_true' , help = "show version" ) parser . add_argument ( 'testcase_paths' , nargs = '*' , help = "testcase file 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 sensitive data." ) parser . add_argument ( '--report-template' , help = "specify report template path." ) parser . add_argument ( '--report-dir' , help = "specify report save directory." ) parser . add_argument ( '--failfast' , action = 'store_true' , default = False , help = "Stop the test run on the first error or failure." ) parser . add_argument ( '--save-tests' , action = 'store_true' , default = False , help = "Save loaded tests and parsed tests to JSON file." ) parser . add_argument ( '--startproject' , help = "Specify new project name." ) parser . add_argument ( '--validate' , nargs = '*' , help = "Validate JSON testcase format." ) parser . add_argument ( '--prettify' , nargs = '*' , help = "Prettify JSON testcase 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 ) project_name = args . startproject if project_name : create_scaffold ( project_name ) exit ( 0 ) runner = HttpRunner ( failfast = args . failfast , save_tests = args . save_tests , report_template = args . report_template , report_dir = args . report_dir ) try : for path in args . testcase_paths : runner . run ( path , dot_env_path = args . dot_env_path ) except Exception : logger . log_error ( "!!!!!!!!!! exception stage: {} !!!!!!!!!!" . format ( runner . exception_stage ) ) raise return 0