Skip to content

Commit 1537d4a

Browse files
authored
Merge pull request #2304 from dhermes/fix-2300
Allow positional arguments tox -e system-tests.
2 parents 71228f7 + 6229b71 commit 1537d4a

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed

CONTRIBUTING.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ Running System Tests
140140
- To run system tests you can execute::
141141

142142
$ tox -e system-tests
143+
$ tox -e system-tests3
143144

144145
or run only system tests for a particular package via::
145146

146147
$ python system_tests/run_system_test.py --package {package}
148+
$ python3 system_tests/run_system_test.py --package {package}
149+
150+
To run a subset of the system tests::
151+
152+
$ tox -e system-tests -- datastore storage
153+
$ python system_tests/attempt_system_tests.py datastore storage
147154

148155
This alone will not run the tests. You'll need to change some local
149156
auth settings and change some configuration in your project to
@@ -243,6 +250,7 @@ Running System Tests
243250
- To run the system tests with the ``pubsub`` emulator::
244251

245252
$ tox -e pubsub-emulator
253+
$ GOOGLE_CLOUD_DISABLE_GRPC=true tox -e pubsub-emulator
246254

247255
If you'd like to run them directly (outside of a ``tox`` environment), first
248256
start the emulator and take note of the process ID::

system_tests/attempt_system_tests.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
"""
4545

4646

47+
from __future__ import print_function
48+
import argparse
4749
import os
4850
import subprocess
4951
import sys
@@ -54,6 +56,7 @@
5456
from run_system_test import run_module_tests
5557

5658

59+
BIGTABLE_API = 'bigtable'
5760
MODULES = ( # ordered from most to least stable
5861
'datastore',
5962
'storage',
@@ -63,15 +66,15 @@
6366
'logging',
6467
'translate',
6568
'monitoring',
69+
BIGTABLE_API,
6670
)
67-
if sys.version_info[:2] == (2, 7):
68-
MODULES += ('bigtable',)
6971

7072
SCRIPTS_DIR = os.path.dirname(__file__)
7173
ROOT_DIR = os.path.abspath(os.path.join(SCRIPTS_DIR, '..'))
7274
ENCRYPTED_KEYFILE = os.path.join(ROOT_DIR, 'system_tests', 'key.json.enc')
7375
ENCRYPTED_KEY_ENV = 'encrypted_c16407eb06cc_key'
7476
ENCRYPTED_INIT_VECTOR_ENV = 'encrypted_c16407eb06cc_iv'
77+
ALL_MODULES = object() # Sentinel for argparser
7578

7679

7780
def check_environment():
@@ -136,11 +139,49 @@ def prepare_to_run():
136139
decrypt_keyfile()
137140

138141

142+
def get_parser():
143+
"""Get an argument parser to determine a list of packages."""
144+
parser = argparse.ArgumentParser(
145+
description='google-cloud tests runner.')
146+
help_msg = ('List of packages to be tested. '
147+
'If left blank, tests all packages.')
148+
parser.add_argument('packages', nargs='*',
149+
default=ALL_MODULES, help=help_msg)
150+
return parser
151+
152+
153+
def get_modules():
154+
"""Get the list of modules names to run system tests for."""
155+
parser = get_parser()
156+
args = parser.parse_args()
157+
if args.packages is ALL_MODULES:
158+
result = list(MODULES)
159+
if sys.version_info[:2] != (2, 7):
160+
result.remove(BIGTABLE_API)
161+
else:
162+
result = []
163+
invalid = []
164+
for package in args.packages:
165+
if package in MODULES:
166+
result.append(package)
167+
else:
168+
invalid.append(package)
169+
170+
if invalid:
171+
msg = 'No system test for packages: ' + ', '.join(invalid)
172+
print(msg, file=sys.stderr)
173+
sys.exit(1)
174+
175+
return result
176+
177+
139178
def main():
140179
"""Run all the system tests if necessary."""
141180
prepare_to_run()
181+
142182
failed_modules = 0
143-
for module in MODULES:
183+
modules = get_modules()
184+
for module in modules:
144185
try:
145186
run_module_tests(module)
146187
except FailedSystemTestModule:

tox.ini

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ passenv = {[testenv:system-tests]passenv}
6060
basepython =
6161
python2.7
6262
commands =
63-
python -c "import shutil; shutil.rmtree('docs/_build/json', ignore_errors=True)"
63+
python -c \
64+
"import shutil; shutil.rmtree('docs/_build/json', ignore_errors=True)"
6465
{toxinidir}/scripts/update_json_docs.sh
6566
deps =
6667
parinx
@@ -78,7 +79,8 @@ passenv =
7879
basepython =
7980
python2.7
8081
commands =
81-
python -c "import shutil; shutil.rmtree('docs/_build', ignore_errors=True)"
82+
python -c \
83+
"import shutil; shutil.rmtree('docs/_build', ignore_errors=True)"
8284
sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html
8385
python {toxinidir}/scripts/verify_included_modules.py --build-root _build
8486
deps =
@@ -88,7 +90,10 @@ deps =
8890
passenv = {[testenv:system-tests]passenv} SPHINX_RELEASE READTHEDOCS
8991

9092
[pep8]
91-
exclude = docs/conf.py,google/cloud/bigtable/_generated*/*,google/cloud/datastore/_generated/*
93+
exclude =
94+
docs/conf.py,
95+
google/cloud/bigtable/_generated*/*,
96+
google/cloud/datastore/_generated/*
9297
verbose = 1
9398

9499
[testenv:lint]
@@ -107,14 +112,14 @@ passenv = {[testenv:system-tests]passenv}
107112
basepython =
108113
python2.7
109114
commands =
110-
python {toxinidir}/system_tests/attempt_system_tests.py
115+
python {toxinidir}/system_tests/attempt_system_tests.py {posargs}
111116
passenv = GOOGLE_* GOOGLE_CLOUD_* TRAVIS* encrypted_*
112117

113118
[testenv:system-tests3]
114119
basepython =
115120
python3.4
116121
commands =
117-
python {toxinidir}/system_tests/attempt_system_tests.py
122+
python {toxinidir}/system_tests/attempt_system_tests.py {posargs}
118123
passenv = {[testenv:system-tests]passenv}
119124

120125
[testenv:datastore-emulator]

0 commit comments

Comments
 (0)