Exemple #1
0
def parse_outputs_option(outputs):
    """Parse value from CLI and validate all outputs are valid.

    Args:
        outputs (str): value gotten from CLI, e.g. "dots,excel".

    Returns:
        set: set of all parsed output handlers.
    """
    if not outputs:
        return None

    requested_handlers = outputs.split(",")

    available_handlers = get_result_handlers()

    non_existing_handlers = set(requested_handlers) - set(available_handlers)

    if non_existing_handlers:
        raise ValueError("The following output handlers are not "
                         "existing: {}.\nAvailable options: {}.".format(
                             ", ".join(non_existing_handlers),
                             ", ".join(available_handlers)))

    return requested_handlers
Exemple #2
0
    def __init__(self,
                 save_state,
                 config,
                 run_delta,
                 outputs,
                 run_name,
                 enable_debug,
                 skip_init=False,
                 workers_number=DEFAULT_WORKERS_NUMBER,
                 *args,
                 **kwargs):
        """Initialize the multiprocess test runner.

        Initializes the workers pool, the request & results queues.
        """
        super(MultiprocessRunner, self).__init__(save_state=save_state,
                                                 config=config,
                                                 run_delta=run_delta,
                                                 outputs=outputs,
                                                 skip_init=skip_init,
                                                 run_name=run_name,
                                                 enable_debug=enable_debug,
                                                 *args,
                                                 **kwargs)
        self.workers_pool = {}

        self.results_queue = None
        self.requests_queue = None
        self.message_handler = None

        self.finished_workers = 0
        self.workers_number = workers_number
        output_handlers = get_result_handlers()

        # Separate monitors from regular output handlers
        self.monitors = [
            handler_name for handler_name in self.outputs
            if issubclass(output_handlers[handler_name], AbstractMonitor)
        ]

        self.outputs = [
            handler_name for handler_name in self.outputs
            if handler_name not in self.monitors
        ]
Exemple #3
0
def pytest_addoption(parser):
    """Add CMD options from Rotest to Pytest."""
    group = parser.getgroup('rotest')

    group.addoption('--config',
                    action='store',
                    dest='config_path',
                    default=DEFAULT_CONFIG_PATH,
                    help='Rotest run configuration file path.')
    group.addoption(
        '--outputs',
        action=OutputHandlersParseAction,
        dest='outputs',
        default=None,
        help="Output handlers separated by comma. Options: {}".format(
            ", ".join(get_result_handlers())))
    group.addoption('--ipdbugger',
                    action='store_true',
                    dest='ipdbugger',
                    default=False,
                    help="Enter ipdb debug mode upon any test exception, "
                    "and enable entering debug mode on Ctrl-Pause "
                    "(Windows) or Ctrl-Quit (Linux).")
Exemple #4
0
def create_client_options_parser():
    """Create option parser for running tests.

    Returns:
        argparse.ArgumentParser: parser for CLI options.
    """
    version = pkg_resources.get_distribution("rotest").version

    parser = argparse.ArgumentParser(
        description="Run tests in a module or directory.")

    parser.add_argument("paths", nargs="*", default=(".", ))
    parser.add_argument("--version",
                        action="version",
                        version="rotest {}".format(version))
    parser.add_argument("--config",
                        "-c",
                        dest="config_path",
                        metavar="path",
                        default=DEFAULT_CONFIG_PATH,
                        help="Test configuration file path")
    parser.add_argument("--save-state",
                        "-s",
                        action="store_true",
                        help="Enable saving state of resources")
    parser.add_argument("--delta",
                        "-d",
                        dest="delta_iterations",
                        metavar="iterations",
                        type=int,
                        help="Enable run of failed tests only - enter the "
                        "number of times the failed tests should be run.")
    parser.add_argument("--processes",
                        "-p",
                        metavar="number",
                        type=int,
                        help="Use multiprocess test runner - specify number "
                        "of worker processes to be created")
    parser.add_argument(
        "--outputs",
        "-o",
        type=parse_outputs_option,
        help="Output handlers separated by comma. Options: {}".format(
            ", ".join(get_result_handlers())))
    parser.add_argument("--filter",
                        "-f",
                        metavar="query",
                        help="Run only tests that match the filter "
                        "expression, e.g. 'Tag1* and not Tag13'")
    parser.add_argument("--name",
                        "-n",
                        metavar="name",
                        dest="run_name",
                        help="Assign a name for current launch")
    parser.add_argument("--list",
                        "-l",
                        action="store_true",
                        help="Print the tests hierarchy and quit")
    parser.add_argument("--failfast",
                        "-F",
                        action="store_true",
                        dest="fail_fast",
                        help="Stop the run on first failure")
    parser.add_argument("--debug",
                        "-D",
                        action="store_true",
                        help="Enter ipdb debug mode upon any test exception")
    parser.add_argument("--skip-init",
                        "-S",
                        action="store_true",
                        help="Skip initialization and validation of resources")
    parser.add_argument("--resources",
                        "-r",
                        metavar="query",
                        help="Specify resources to request be attributes, "
                        "e.g. '-r res1.group=QA,res2.comment=CI'")

    for entry_point in \
            pkg_resources.iter_entry_points("rotest.cli_client_parsers"):
        core_log.debug("Applying entry point %s", entry_point.name)
        extension_parser = entry_point.load()
        extension_parser(parser)

    return parser