diff --git a/test/runner/lib/delegation.py b/test/runner/lib/delegation.py index 7f195d97b06..726397b670b 100644 --- a/test/runner/lib/delegation.py +++ b/test/runner/lib/delegation.py @@ -15,6 +15,7 @@ from lib.executor import ( SubprocessError, ShellConfig, TestConfig, + SanityConfig, create_shell_command, ) @@ -354,6 +355,9 @@ def generate_command(args, path, options, exclude, require): if isinstance(args, ShellConfig): cmd = create_shell_command(cmd) + elif isinstance(args, SanityConfig): + if args.base_branch: + cmd += ['--base-branch', args.base_branch] return cmd @@ -382,6 +386,10 @@ def filter_options(args, argv, options, exclude, require): '--changed-from': 1, '--changed-path': 1, }) + elif isinstance(args, SanityConfig): + options.update({ + '--base-branch': 1, + }) remaining = 0 diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 04cd065a637..79156199b08 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -35,6 +35,7 @@ from lib.util import ( ApplicationWarning, ApplicationError, SubprocessError, + MissingEnvironmentVariable, display, run_command, deepest_path, @@ -796,12 +797,12 @@ def command_sanity_validate_modules(args, targets): if skip_paths: cmd += ['--exclude', '^(%s)' % '|'.join(skip_paths)] - if is_shippable(): + if args.base_branch: cmd.extend([ - '--base-branch', os.environ['BASE_BRANCH'] + '--base-branch', args.base_branch, ]) else: - display.warning("Cannot perform module comparison against the base branch when running locally") + display.warning('Cannot perform module comparison against the base branch. Base branch not detected when running locally.') run_command(args, cmd, env=env) @@ -1378,6 +1379,16 @@ class SanityConfig(TestConfig): self.skip_test = args.skip_test # type: list [str] self.list_tests = args.list_tests # type: bool + if args.base_branch: + self.base_branch = args.base_branch # str + elif is_shippable(): + try: + self.base_branch = os.environ['BASE_BRANCH'] # str + except KeyError as ex: + raise MissingEnvironmentVariable(name=ex.args[0]) + else: + self.base_branch = '' + class IntegrationConfig(TestConfig): """Configuration for the integration command.""" diff --git a/test/runner/test.py b/test/runner/test.py index e08b6ccdcc6..c6a5ed613a1 100755 --- a/test/runner/test.py +++ b/test/runner/test.py @@ -285,6 +285,9 @@ def parse_args(): choices=SUPPORTED_PYTHON_VERSIONS, help='python version: %s' % ', '.join(SUPPORTED_PYTHON_VERSIONS)) + sanity.add_argument('--base-branch', + help=argparse.SUPPRESS) + add_extra_docker_options(sanity, integration=False) shell = subparsers.add_parser('shell',