From 6229b7193da8de76040cfaa926914629558b861e Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 12 Sep 2016 13:42:07 -0700 Subject: [PATCH] Allow positional arguments tox -e system-tests. Fixes #2300. --- CONTRIBUTING.rst | 8 +++++ system_tests/attempt_system_tests.py | 47 ++++++++++++++++++++++++++-- tox.ini | 15 ++++++--- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 7b0eabd3411d..c1d755bb354f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -140,10 +140,17 @@ Running System Tests - To run system tests you can execute:: $ tox -e system-tests + $ tox -e system-tests3 or run only system tests for a particular package via:: $ python system_tests/run_system_test.py --package {package} + $ python3 system_tests/run_system_test.py --package {package} + + To run a subset of the system tests:: + + $ tox -e system-tests -- datastore storage + $ python system_tests/attempt_system_tests.py datastore storage This alone will not run the tests. You'll need to change some local auth settings and change some configuration in your project to @@ -243,6 +250,7 @@ Running System Tests - To run the system tests with the ``pubsub`` emulator:: $ tox -e pubsub-emulator + $ GOOGLE_CLOUD_DISABLE_GRPC=true tox -e pubsub-emulator If you'd like to run them directly (outside of a ``tox`` environment), first start the emulator and take note of the process ID:: diff --git a/system_tests/attempt_system_tests.py b/system_tests/attempt_system_tests.py index c5c9ef2a843e..70dba5147868 100644 --- a/system_tests/attempt_system_tests.py +++ b/system_tests/attempt_system_tests.py @@ -44,6 +44,8 @@ """ +from __future__ import print_function +import argparse import os import subprocess import sys @@ -54,6 +56,7 @@ from run_system_test import run_module_tests +BIGTABLE_API = 'bigtable' MODULES = ( # ordered from most to least stable 'datastore', 'storage', @@ -63,15 +66,15 @@ 'logging', 'translate', 'monitoring', + BIGTABLE_API, ) -if sys.version_info[:2] == (2, 7): - MODULES += ('bigtable',) SCRIPTS_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.abspath(os.path.join(SCRIPTS_DIR, '..')) ENCRYPTED_KEYFILE = os.path.join(ROOT_DIR, 'system_tests', 'key.json.enc') ENCRYPTED_KEY_ENV = 'encrypted_c16407eb06cc_key' ENCRYPTED_INIT_VECTOR_ENV = 'encrypted_c16407eb06cc_iv' +ALL_MODULES = object() # Sentinel for argparser def check_environment(): @@ -136,11 +139,49 @@ def prepare_to_run(): decrypt_keyfile() +def get_parser(): + """Get an argument parser to determine a list of packages.""" + parser = argparse.ArgumentParser( + description='google-cloud tests runner.') + help_msg = ('List of packages to be tested. ' + 'If left blank, tests all packages.') + parser.add_argument('packages', nargs='*', + default=ALL_MODULES, help=help_msg) + return parser + + +def get_modules(): + """Get the list of modules names to run system tests for.""" + parser = get_parser() + args = parser.parse_args() + if args.packages is ALL_MODULES: + result = list(MODULES) + if sys.version_info[:2] != (2, 7): + result.remove(BIGTABLE_API) + else: + result = [] + invalid = [] + for package in args.packages: + if package in MODULES: + result.append(package) + else: + invalid.append(package) + + if invalid: + msg = 'No system test for packages: ' + ', '.join(invalid) + print(msg, file=sys.stderr) + sys.exit(1) + + return result + + def main(): """Run all the system tests if necessary.""" prepare_to_run() + failed_modules = 0 - for module in MODULES: + modules = get_modules() + for module in modules: try: run_module_tests(module) except FailedSystemTestModule: diff --git a/tox.ini b/tox.ini index 01e473331b59..0cd578f82682 100644 --- a/tox.ini +++ b/tox.ini @@ -60,7 +60,8 @@ passenv = {[testenv:system-tests]passenv} basepython = python2.7 commands = - python -c "import shutil; shutil.rmtree('docs/_build/json', ignore_errors=True)" + python -c \ + "import shutil; shutil.rmtree('docs/_build/json', ignore_errors=True)" {toxinidir}/scripts/update_json_docs.sh deps = parinx @@ -78,7 +79,8 @@ passenv = basepython = python2.7 commands = - python -c "import shutil; shutil.rmtree('docs/_build', ignore_errors=True)" + python -c \ + "import shutil; shutil.rmtree('docs/_build', ignore_errors=True)" sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html python {toxinidir}/scripts/verify_included_modules.py --build-root _build deps = @@ -88,7 +90,10 @@ deps = passenv = {[testenv:system-tests]passenv} SPHINX_RELEASE READTHEDOCS [pep8] -exclude = docs/conf.py,google/cloud/bigtable/_generated*/*,google/cloud/datastore/_generated/* +exclude = + docs/conf.py, + google/cloud/bigtable/_generated*/*, + google/cloud/datastore/_generated/* verbose = 1 [testenv:lint] @@ -107,14 +112,14 @@ passenv = {[testenv:system-tests]passenv} basepython = python2.7 commands = - python {toxinidir}/system_tests/attempt_system_tests.py + python {toxinidir}/system_tests/attempt_system_tests.py {posargs} passenv = GOOGLE_* GOOGLE_CLOUD_* TRAVIS* encrypted_* [testenv:system-tests3] basepython = python3.4 commands = - python {toxinidir}/system_tests/attempt_system_tests.py + python {toxinidir}/system_tests/attempt_system_tests.py {posargs} passenv = {[testenv:system-tests]passenv} [testenv:datastore-emulator]