Skip to content

Commit 56c1af2

Browse files
committed
Allowing local env. vars. to be used for running unit tests.
1 parent 83c197c commit 56c1af2

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

scripts/run_unit_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from script_utils import get_changed_packages
3131
from script_utils import in_travis
3232
from script_utils import in_travis_pr
33+
from script_utils import local_diff_branch
3334
from script_utils import travis_branch
3435

3536

@@ -119,6 +120,8 @@ def get_test_packages():
119120
Filters the package list in the following order:
120121
121122
* Check command line for packages passed in as positional arguments
123+
* Check if the the local remote and local branch environment variables
124+
have been set to specify a remote branch to diff against.
122125
* Check if in Travis, then limit the subset based on changes
123126
in a Pull Request ("push" builds to branches may not have
124127
any filtering)
@@ -129,12 +132,15 @@ def get_test_packages():
129132
need be run.
130133
"""
131134
all_packages = get_package_directories()
135+
local_diff = local_diff_branch()
132136

133137
parser = get_parser()
134138
args = parser.parse_args()
135139
if args.packages is not UNSET_SENTINEL:
136140
verify_packages(args.packages, all_packages)
137141
return sorted(args.packages)
142+
elif local_diff is not None:
143+
return get_changed_packages('HEAD', local_diff, all_packages)
138144
elif in_travis():
139145
return get_travis_directories(all_packages)
140146
else:

scripts/script_utils.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ def get_changed_packages(blob_name1, blob_name2, package_list):
163163
return sorted(result)
164164

165165

166+
def local_diff_branch():
167+
"""Get a remote branch to diff against in a local checkout.
168+
169+
Checks if the the local remote and local branch environment
170+
variables specify a remote branch.
171+
172+
:rtype: str
173+
:returns: The diffbase `{remote}/{branch}` if the environment
174+
variables are defined. If not, returns ``None``.
175+
"""
176+
# Only allow specified remote and branch in local dev.
177+
remote = os.getenv(LOCAL_REMOTE_ENV)
178+
branch = os.getenv(LOCAL_BRANCH_ENV)
179+
if remote is not None and branch is not None:
180+
return '%s/%s' % (remote, branch)
181+
182+
166183
def get_affected_files(allow_limited=True):
167184
"""Gets a list of files in the repository.
168185
@@ -195,11 +212,7 @@ def get_affected_files(allow_limited=True):
195212
if in_travis_pr():
196213
diff_base = travis_branch()
197214
else:
198-
# Only allow specified remote and branch in local dev.
199-
remote = os.getenv(LOCAL_REMOTE_ENV)
200-
branch = os.getenv(LOCAL_BRANCH_ENV)
201-
if remote is not None and branch is not None:
202-
diff_base = '%s/%s' % (remote, branch)
215+
diff_base = local_diff_branch()
203216

204217
if diff_base is not None and allow_limited:
205218
result = subprocess.check_output(['git', 'diff', '--name-only',

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ skip_install =
121121
py34: True
122122
py35: True
123123
isolated-cover: True
124-
passenv = TRAVIS*
124+
passenv = TRAVIS* GOOGLE_CLOUD_*
125125

126126
[testenv:isolated-cover]
127127
commands =

0 commit comments

Comments
 (0)