Пример #1
0
    def get_reporters(self, options, plugin_modules):
        reporters = []
        if options.disable_color:
            reporters.append(test_logger.ColorlessTextTestLogger(options))
        else:
            reporters.append(test_logger.TextTestLogger(options))

        for plugin in plugin_modules:
            if hasattr(plugin, "build_test_reporters"):
                reporters += plugin.build_test_reporters(options)
        return reporters
Пример #2
0
def parse_test_runner_command_line_args(plugin_modules, args):
    """Parse command line args for the TestRunner to determine verbosity and other stuff"""
    parser = OptionParser(usage="%prog <test path> [options]",
                          version="%%prog %s" % testify.__version__)

    parser.set_defaults(verbosity=test_logger.VERBOSITY_NORMAL)
    parser.add_option("-s",
                      "--silent",
                      action="store_const",
                      const=test_logger.VERBOSITY_SILENT,
                      dest="verbosity")
    parser.add_option("-v",
                      "--verbose",
                      action="store_const",
                      const=test_logger.VERBOSITY_VERBOSE,
                      dest="verbosity")
    parser.add_option(
        "-d",
        "--ipdb",
        action="store_true",
        dest="debugger",
        help=
        "Enter post mortem debugging mode with ipdb in the case of an exception thrown in a test method or fixture method."
    )

    parser.add_option("-i",
                      "--include-suite",
                      action="append",
                      dest="suites_include",
                      type="string",
                      default=[])
    parser.add_option("-x",
                      "--exclude-suite",
                      action="append",
                      dest="suites_exclude",
                      type="string",
                      default=[])
    parser.add_option("-q",
                      "--require-suite",
                      action="append",
                      dest="suites_require",
                      type="string",
                      default=[])

    parser.add_option("--list-suites", action="store_true", dest="list_suites")
    parser.add_option("--list-tests", action="store_true", dest="list_tests")

    parser.add_option("--label",
                      action="store",
                      dest="label",
                      type="string",
                      help="label for this test run")

    parser.add_option("--bucket", action="store", dest="bucket", type="int")
    parser.add_option("--bucket-count",
                      action="store",
                      dest="bucket_count",
                      type="int")
    parser.add_option("--bucket-overrides-file",
                      action="store",
                      dest="bucket_overrides_file",
                      default=None)
    parser.add_option("--bucket-salt",
                      action="store",
                      dest="bucket_salt",
                      default=None)

    parser.add_option("--summary", action="store_true", dest="summary_mode")
    parser.add_option("--no-color",
                      action="store_true",
                      dest="disable_color",
                      default=bool(not os.isatty(sys.stdout.fileno())))

    parser.add_option("--log-file",
                      action="store",
                      dest="log_file",
                      type="string",
                      default=None)
    parser.add_option("--log-level",
                      action="store",
                      dest="log_level",
                      type="string",
                      default="INFO")
    parser.add_option(
        '--print-log',
        action="append",
        dest="print_loggers",
        type="string",
        default=[],
        help="Direct logging output for these loggers to the console")

    parser.add_option(
        '--serve',
        action="store",
        dest="serve_port",
        type="int",
        default=None,
        help="Run in server mode, listening on this port for testify clients.")
    parser.add_option(
        '--connect',
        action="store",
        dest="connect_addr",
        type="string",
        default=None,
        metavar="HOST:PORT",
        help="Connect to a testify server (testify --serve) at this HOST:PORT")
    parser.add_option(
        '--revision',
        action="store",
        dest="revision",
        type="string",
        default=None,
        help=
        "With --serve, refuses clients that identify with a different or no revision. In client mode, sends the revision number to the server for verification."
    )
    parser.add_option(
        '--retry-limit',
        action="store",
        dest="retry_limit",
        type="int",
        default=60,
        help="Number of times to try connecting to the server before exiting.")
    parser.add_option(
        '--retry-interval',
        action="store",
        dest="retry_interval",
        type="int",
        default=2,
        help="Interval, in seconds, between trying to connect to the server.")
    parser.add_option(
        '--reconnect-retry-limit',
        action="store",
        dest="reconnect_retry_limit",
        type="int",
        default=5,
        help=
        "Number of times to try reconnecting to the server before exiting if we have previously connected."
    )

    parser.add_option('--failure-limit',
                      action="store",
                      dest="failure_limit",
                      type="int",
                      default=None,
                      help="Quit after this many test failures.")
    parser.add_option(
        '--runner-timeout',
        action="store",
        dest="runner_timeout",
        type="int",
        default=300,
        help=
        "How long to wait to wait for activity from a test runner before requeuing the tests it has checked out."
    )
    parser.add_option(
        '--server-timeout',
        action="store",
        dest="server_timeout",
        type="int",
        default=300,
        help=
        "How long to wait after the last activity from any test runner before shutting down."
    )

    parser.add_option(
        '--server-shutdown-delay',
        action='store',
        dest='shutdown_delay_for_connection_close',
        type="float",
        default=0.01,
        help=
        "How long to wait (in seconds) for data to finish writing to sockets before shutting down the server."
    )
    parser.add_option(
        '--server-shutdown-delay-outstanding-runners',
        action='store',
        dest='shutdown_delay_for_outstanding_runners',
        type='int',
        default=5,
        help=
        "How long to wait (in seconds) for all clients to check for new tests before shutting down the server."
    )

    parser.add_option(
        '--runner-id',
        action="store",
        dest="runner_id",
        type="string",
        default="%s-%d" % (socket.gethostname(), os.getpid()),
        help=
        "With --connect, an identity passed to the server on each request. Passed to the server's test reporters. Defaults to <HOST>-<PID>."
    )

    parser.add_option(
        '--replay-json',
        action="store",
        dest="replay_json",
        type="string",
        default=None,
        help=
        "Instead of discovering and running tests, read a file with one JSON-encoded test result dictionary per line, and report each line to test reporters as if we had just run that test."
    )
    parser.add_option(
        '--replay-json-inline',
        action="append",
        dest="replay_json_inline",
        type="string",
        metavar="JSON_OBJECT",
        help=
        "Similar to --replay-json, but allows result objects to be passed on the command line. May be passed multiple times. If combined with --replay-json, inline results get reported first."
    )

    parser.add_option(
        '--rerun-test-file',
        action="store",
        dest="rerun_test_file",
        type="string",
        default=None,
        help=
        "Rerun tests listed in FILE in order. One test per line, in the format 'path.to.class ClassName.test_method_name'. Consecutive tests in the same class will be run on the same test class instance."
    )

    # Add in any additional options
    for plugin in plugin_modules:
        if hasattr(plugin, 'add_command_line_options'):
            plugin.add_command_line_options(parser)

    (options, args) = parser.parse_args(args)
    if len(args) < 1 and not options.connect_addr:
        parser.error("Test path required unless --connect specified.")

    if options.connect_addr and options.serve_port:
        parser.error("--serve and --connect are mutually exclusive.")

    test_path, module_method_overrides = _parse_test_runner_command_line_module_method_overrides(
        args)

    if pwd.getpwuid(os.getuid()).pw_name == 'buildbot':
        options.disable_color = True

    if options.list_suites:
        runner_action = ACTION_LIST_SUITES
    elif options.list_tests:
        runner_action = ACTION_LIST_TESTS
    else:
        runner_action = ACTION_RUN_TESTS

    reporters = []
    if options.disable_color:
        reporters.append(test_logger.ColorlessTextTestLogger(options))
    else:
        reporters.append(test_logger.TextTestLogger(options))

    for plugin in plugin_modules:
        if hasattr(plugin, "build_test_reporters"):
            reporters += plugin.build_test_reporters(options)

    test_runner_args = {
        'debugger': options.debugger,
        'suites_include': options.suites_include,
        'suites_exclude': options.suites_exclude,
        'suites_require': options.suites_require,
        'failure_limit': options.failure_limit,
        'module_method_overrides': module_method_overrides,
        'test_reporters': reporters,  # Should be pushed into plugin
        'options': options,
        'plugin_modules': plugin_modules
    }

    return runner_action, test_path, test_runner_args, options