def run_test_job()

in src/start_testbuilds.py [0:0]


def run_test_job(commit, codebuild_project, images_str=""):
    test_env_file = constants.TEST_ENV_PATH
    if not os.path.exists(test_env_file):
        raise FileNotFoundError(
            f"{test_env_file} not found. This is required to set test environment variables"
            f" for test jobs. Failing the build."
        )

    with open(test_env_file) as test_env_file:
        env_overrides = json.load(test_env_file)

    # For EC2 tests, if HEAVY_INSTANCE_EC2_TESTS_ENABLED is True, the test job will run tests on
    # large/expensive instance types as well as small/regular instance types, based on the config of
    # the test function. If False, the test job will only run tests on small/regular instance types.
    are_heavy_instance_ec2_tests_enabled = (
        config.are_heavy_instance_ec2_tests_enabled() and "ec2" in codebuild_project
    )

    if config.is_deep_canary_mode_enabled():
        env_overrides.append({"name": "DEEP_CANARY_MODE", "value": "true", "type": "PLAINTEXT"})

    pr_num = os.getenv("PR_NUMBER")
    LOGGER.debug(f"pr_num {pr_num}")
    env_overrides.extend(
        [
            # Adding FRAMEWORK to env variables to enable simulation of deep canary tests in PR
            {"name": "FRAMEWORK", "value": os.getenv("FRAMEWORK", ""), "type": "PLAINTEXT"},
            # Adding IMAGE_TYPE to env variables to enable simulation of deep canary tests in PR
            {"name": "IMAGE_TYPE", "value": os.getenv("IMAGE_TYPE", ""), "type": "PLAINTEXT"},
            {"name": "DLC_IMAGES", "value": images_str, "type": "PLAINTEXT"},
            {"name": "PR_NUMBER", "value": pr_num, "type": "PLAINTEXT"},
            # NIGHTLY_PR_TEST_MODE is passed as an env variable here because it is more convenient to set this in
            # dlc_developer_config, and imports during test execution are less complicated when there are fewer
            # cross-references between test and src code.
            {
                "name": "NIGHTLY_PR_TEST_MODE",
                "value": str(config.is_nightly_pr_test_mode_enabled()),
                "type": "PLAINTEXT",
            },
            # USE_SCHEDULER is passed as an env variable here because it is more convenient to set this in
            # dlc_developer_config, compared to having another config file under dlc/tests/.
            {
                "name": "USE_SCHEDULER",
                "value": str(config.is_scheduler_enabled()),
                "type": "PLAINTEXT",
            },
            # SM_EFA_TEST_INSTANCE_TYPE is passed to SM test job to pick a matching instance type as defined by user
            {
                "name": "SM_EFA_TEST_INSTANCE_TYPE",
                "value": config.get_sagemaker_remote_efa_instance_type(),
                "type": "PLAINTEXT",
            },
            {
                "name": "HEAVY_INSTANCE_EC2_TESTS_ENABLED",
                "value": str(are_heavy_instance_ec2_tests_enabled),
                "type": "PLAINTEXT",
            },
            {
                "name": "FRAMEWORK_BUILDSPEC_FILE",
                "value": config.get_buildspec_override() or os.getenv("FRAMEWORK_BUILDSPEC_FILE"),
                "type": "PLAINTEXT",
            },
        ]
    )
    LOGGER.debug(f"env_overrides dict: {env_overrides}")

    client = boto3.client("codebuild")
    return client.start_build(
        projectName=codebuild_project,
        environmentVariablesOverride=env_overrides,
        sourceVersion=commit,
    )