(
    ctx: click.Context,
    config: Optional[Path],
    project_root: Optional[Path],  # None if the project root cant be found
    config_path: Optional[Path],  # added by callback on '--config' option
    path: Tuple[str],
    exclude: Tuple[str],
    search: Optional[str],
    tags: Optional[Expression],
    fail_limit: Optional[int],
    test_output_style: str,
    progress_style: List[str],
    order: str,
    capture_output: bool,
    show_slowest: int,
    show_diff_symbols: bool,
    dry_run: bool,
    hook_module: Tuple[str],
)
Run tests.
Run tests.
Run tests .
def test(
    ctx: click.Context,
    config: Optional[Path],
    project_root: Optional[Path],  # None if the project root cant be found
    config_path: Optional[Path],  # added by callback on '--config' option
    path: Tuple[str],
    exclude: Tuple[str],
    search: Optional[str],
    tags: Optional[Expression],
    fail_limit: Optional[int],
    test_output_style: str,
    progress_style: List[str],
    order: str,
    capture_output: bool,
    show_slowest: int,
    show_diff_symbols: bool,
    dry_run: bool,
    hook_module: Tuple[str],
):
    """Run tests."""
    config_params = ctx.params.copy()
    config_params.pop("config")

    config = Config(**config_params, plugin_config=config_params.get("plugins", {}))

    test_output_style = TestOutputStyle(test_output_style)
    progress_styles = [TestProgressStyle(ps) for ps in progress_style]

    init_breakpointhooks(pdb, sys)
    start_run = default_timer()

    print_before: Tuple[ConsoleRenderable] = plugins.hook.before_session(config=config)

    configure_path(project_root)
    paths = [Path(p) for p in path]
    mod_infos = get_info_for_modules(paths, exclude)
    modules = load_modules(mod_infos)
    unfiltered_tests = get_tests_in_modules(modules, capture_output)
    plugins.hook.preprocess_tests(config=config, collected_tests=unfiltered_tests)
    filtered_tests = filter_tests(unfiltered_tests, query=search, tag_expr=tags)
    if config.order == "random":
        shuffle(filtered_tests)

    tests = rewrite_assertions_in_tests(filtered_tests)

    time_to_collect_secs = default_timer() - start_run

    suite = Suite(tests=tests)
    test_results = suite.generate_test_runs(
        dry_run=dry_run, capture_output=capture_output
    )
    rich_console.print(
        SessionPrelude(
            time_to_collect_secs=time_to_collect_secs,
            num_tests_collected=suite.num_tests_with_parameterisation,
            num_fixtures_collected=len(_DEFINED_FIXTURES),
            config_path=config_path,
        )
    )
    writer = TestResultWriter(
        console=rich_console,
        suite=suite,
        test_output_style=test_output_style,
        progress_styles=progress_styles,
        config_path=config_path,
        show_diff_symbols=show_diff_symbols,
    )
    for renderable in print_before:
        rich_console.print(renderable)
    test_results = writer.output_all_test_results(test_results, fail_limit=fail_limit)
    exit_code = get_exit_code(test_results)
    time_taken = default_timer() - start_run

    render_afters: Tuple[ConsoleRenderable] = plugins.hook.after_session(
        config=config, test_results=test_results, status_code=exit_code
    )
    for renderable in render_afters:
        rich_console.print(renderable)

    writer.output_test_result_summary(test_results, time_taken, show_slowest)
    sys.exit(exit_code.value)
def test ( ctx : click . Context , config : Optional [ Path ] , project_root : Optional [ Path ] , # None if the project root cant be found config_path : Optional [ Path ] , # added by callback on '--config' option path : Tuple [ str ] , exclude : Tuple [ str ] , search : Optional [ str ] , tags : Optional [ Expression ] , fail_limit : Optional [ int ] , test_output_style : str , progress_style : List [ str ] , order : str , capture_output : bool , show_slowest : int , show_diff_symbols : bool , dry_run : bool , hook_module : Tuple [ str ] , ) : config_params = ctx . params . copy ( ) config_params . pop ( "config" ) config = Config ( * * config_params , plugin_config = config_params . get ( "plugins" , { } ) ) test_output_style = TestOutputStyle ( test_output_style ) progress_styles = [ TestProgressStyle ( ps ) for ps in progress_style ] init_breakpointhooks ( pdb , sys ) start_run = default_timer ( ) print_before : Tuple [ ConsoleRenderable ] = plugins . hook . before_session ( config = config ) configure_path ( project_root ) paths = [ Path ( p ) for p in path ] mod_infos = get_info_for_modules ( paths , exclude ) modules = load_modules ( mod_infos ) unfiltered_tests = get_tests_in_modules ( modules , capture_output ) plugins . hook . preprocess_tests ( config = config , collected_tests = unfiltered_tests ) filtered_tests = filter_tests ( unfiltered_tests , query = search , tag_expr = tags ) if config . order == "random" : shuffle ( filtered_tests ) tests = rewrite_assertions_in_tests ( filtered_tests ) time_to_collect_secs = default_timer ( ) - start_run suite = Suite ( tests = tests ) test_results = suite . generate_test_runs ( dry_run = dry_run , capture_output = capture_output ) rich_console . print ( SessionPrelude ( time_to_collect_secs = time_to_collect_secs , num_tests_collected = suite . num_tests_with_parameterisation , num_fixtures_collected = len ( _DEFINED_FIXTURES ) , config_path = config_path , ) ) writer = TestResultWriter ( console = rich_console , suite = suite , test_output_style = test_output_style , progress_styles = progress_styles , config_path = config_path , show_diff_symbols = show_diff_symbols , ) for renderable in print_before : rich_console . print ( renderable ) test_results = writer . output_all_test_results ( test_results , fail_limit = fail_limit ) exit_code = get_exit_code ( test_results ) time_taken = default_timer ( ) - start_run render_afters : Tuple [ ConsoleRenderable ] = plugins . hook . after_session ( config = config , test_results = test_results , status_code = exit_code ) for renderable in render_afters : rich_console . print ( renderable ) writer . output_test_result_summary ( test_results , time_taken , show_slowest ) sys . exit ( exit_code . value )