diff --git a/scripts/run_unit_tests.py b/scripts/run_unit_tests.py index 4254f2f8e6b9..869a520fb081 100644 --- a/scripts/run_unit_tests.py +++ b/scripts/run_unit_tests.py @@ -30,6 +30,7 @@ from script_utils import get_changed_packages from script_utils import in_travis from script_utils import in_travis_pr +from script_utils import local_diff_branch from script_utils import travis_branch @@ -119,6 +120,8 @@ def get_test_packages(): Filters the package list in the following order: * Check command line for packages passed in as positional arguments + * Check if the the local remote and local branch environment variables + have been set to specify a remote branch to diff against. * Check if in Travis, then limit the subset based on changes in a Pull Request ("push" builds to branches may not have any filtering) @@ -129,12 +132,15 @@ def get_test_packages(): need be run. """ all_packages = get_package_directories() + local_diff = local_diff_branch() parser = get_parser() args = parser.parse_args() if args.packages is not UNSET_SENTINEL: verify_packages(args.packages, all_packages) return sorted(args.packages) + elif local_diff is not None: + return get_changed_packages('HEAD', local_diff, all_packages) elif in_travis(): return get_travis_directories(all_packages) else: diff --git a/scripts/script_utils.py b/scripts/script_utils.py index 370408e6faa3..b64f897d4a93 100644 --- a/scripts/script_utils.py +++ b/scripts/script_utils.py @@ -163,6 +163,23 @@ def get_changed_packages(blob_name1, blob_name2, package_list): return sorted(result) +def local_diff_branch(): + """Get a remote branch to diff against in a local checkout. + + Checks if the the local remote and local branch environment + variables specify a remote branch. + + :rtype: str + :returns: The diffbase `{remote}/{branch}` if the environment + variables are defined. If not, returns ``None``. + """ + # Only allow specified remote and branch in local dev. + remote = os.getenv(LOCAL_REMOTE_ENV) + branch = os.getenv(LOCAL_BRANCH_ENV) + if remote is not None and branch is not None: + return '%s/%s' % (remote, branch) + + def get_affected_files(allow_limited=True): """Gets a list of files in the repository. @@ -195,11 +212,7 @@ def get_affected_files(allow_limited=True): if in_travis_pr(): diff_base = travis_branch() else: - # Only allow specified remote and branch in local dev. - remote = os.getenv(LOCAL_REMOTE_ENV) - branch = os.getenv(LOCAL_BRANCH_ENV) - if remote is not None and branch is not None: - diff_base = '%s/%s' % (remote, branch) + diff_base = local_diff_branch() if diff_base is not None and allow_limited: result = subprocess.check_output(['git', 'diff', '--name-only', diff --git a/tox.ini b/tox.ini index c0783749c4c4..69118912797b 100644 --- a/tox.ini +++ b/tox.ini @@ -121,7 +121,7 @@ skip_install = py34: True py35: True isolated-cover: True -passenv = TRAVIS* +passenv = TRAVIS* GOOGLE_CLOUD_* [testenv:isolated-cover] commands =