Exemplo n.º 1
0
def run(
    ctx,
    manifest,
    tests,
    dry_run: bool,
    interactive,
    output: str,
    verbose,
    debug,
    simple_test_selector,
    keep_tmpdir,
    tmpdir,
    mysql_client: bool,
    mysql_schemas,
    devdb: str,
    discovered_tests,
) -> None:
    manifest = os.path.abspath(manifest)
    if is_libfb_present():
        from eden.mononoke.tests.integration.facebook.lib_buck import find_buck_out
        from libfb.py.log import set_simple_logging

        def load_manifest_env(manifest_path: str) -> Dict[str, str]:
            buck_out = find_buck_out(manifest_path)

            with open(manifest_path) as f:
                manifest_env = json.load(f)

            def process_value(key: str, value: str, buck_out: str) -> str:
                if key.startswith("VERBATIM_"):
                    return value
                return os.path.join(buck_out, value)

            return {
                k: process_value(k, v, buck_out)
                for k, v in manifest_env.items()
            }

        set_simple_logging(logging.INFO)
        manifest_env: ManifestEnv = load_manifest_env(manifest)
    else:
        with open(manifest) as f:
            manifest_env: ManifestEnv = json.load(f)

    maybe_use_local_test_paths(manifest_env)

    if dry_run and discovered_tests:
        return format_discovered_tests(list(discovered_tests), ctx, output)

    test_flags: TestFlags = TestFlags(
        interactive,
        verbose,
        debug,
        keep_tmpdir,
        tmpdir,
        disable_all_network_access=(
            # NOTE: We need network to talk to MySQL
            not debug and not mysql_client
            and "DISABLE_ALL_NETWORK_ACCESS" in manifest_env),
    )

    selected_tests: List[str] = []
    if simple_test_selector is not None and tests:
        raise click.BadParameter(
            f"Found --simple-test-selector {simple_test_selector}. Use either --simple-test-selector, or [...TESTS]",
            ctx,
        )
    elif simple_test_selector is not None:
        suite, test = simple_test_selector.split(",", 1)
        if suite != SUITE:
            raise click.BadParameter(
                'suite should always be "%s"' % SUITE,
                ctx,
                param_hint="simple_test_selector",
            )
        selected_tests.append(test)
    else:
        selected_tests.extend(tests)

    try:
        from eden.mononoke.tests.integration.facebook.lib_runner import fb_test_context
    except ImportError:
        run_tests(ctx,
                  manifest_env,
                  output,
                  selected_tests,
                  test_flags,
                  test_env={})
    else:
        with fb_test_context(ctx, dry_run, mysql_client, mysql_schemas, devdb,
                             selected_tests) as test_env:
            run_tests(ctx, manifest_env, output, selected_tests, test_flags,
                      test_env)
Exemplo n.º 2
0
def run(
    ctx,
    manifest,
    tests,
    dry_run,
    interactive,
    output,
    verbose,
    debug,
    simple_test_selector,
    keep_tmpdir,
    tmpdir,
    mysql_client,
    mysql_schemas,
    devdb,
    py3_skip_list,
):
    manifest = os.path.abspath(manifest)
    if is_libfb_present():
        from eden.mononoke.tests.integration.facebook.lib_runner import (
            load_manifest_env, )
        from libfb.py.log import set_simple_logging

        set_simple_logging(logging.INFO)
        manifest_env: ManifestEnv = load_manifest_env(manifest)
    else:
        with open(manifest) as f:
            manifest_env: ManifestEnv = json.load(f)

    maybe_use_local_test_paths(manifest_env)

    if dry_run:
        return run_discover_tests(ctx, manifest_env, output, mysql_client,
                                  py3_skip_list)

    test_flags: TestFlags = TestFlags(
        interactive,
        verbose,
        debug,
        keep_tmpdir,
        tmpdir,
        disable_all_network_access=(
            # NOTE: We need network to talk to MySQL
            not debug and not mysql_client
            and "DISABLE_ALL_NETWORK_ACCESS" in manifest_env),
    )

    selected_tests: List[str] = []
    if simple_test_selector is not None and tests:
        raise click.BadParameter(
            "Use either --simple-test-selector, or [...TESTS]", ctx)
    elif simple_test_selector is not None:
        suite, test = simple_test_selector.split(",", 1)
        if suite != "run-tests":
            raise click.BadParameter(
                'suite should always be "%s"' % SUITE,
                ctx,
                param_hint="simple_test_selector",
            )
        selected_tests.append(test)
    else:
        selected_tests.extend(tests)

    if is_libfb_present():
        from eden.mononoke.tests.integration.facebook.lib_runner import fb_test_context

        with fb_test_context(ctx, dry_run, mysql_client, mysql_schemas, devdb,
                             selected_tests) as test_env:
            run_tests(ctx, manifest_env, output, selected_tests, test_flags,
                      test_env)
    else:
        run_tests(ctx,
                  manifest_env,
                  output,
                  selected_tests,
                  test_flags,
                  test_env={})