From e6cc9c7a253464e17abfd0fbd7dd5f1a52df36da Mon Sep 17 00:00:00 2001 From: Jan Tattermusch <jtattermusch@google.com> Date: Mon, 7 Mar 2016 12:36:38 -0800 Subject: [PATCH] custom test target for parallel test running --- setup.py | 1 + src/python/grpcio/commands.py | 35 +++++++++++++++++++++++++++++++++++ tools/run_tests/run_python.sh | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cfb578e215..e1abe7fd8f 100644 --- a/setup.py +++ b/setup.py @@ -165,6 +165,7 @@ COMMAND_CLASS = { 'build_tagged_ext': precompiled.BuildTaggedExt, 'gather': commands.Gather, 'run_interop': commands.RunInterop, + 'test_lite': commands.TestLite } # Ensure that package data is copied over before any commands have been run: diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index aa29c728f2..ec116f58ab 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -264,6 +264,41 @@ class Gather(setuptools.Command): self.distribution.fetch_build_eggs(self.distribution.tests_require) +class TestLite(setuptools.Command): + """Command to run tests without fetching or building anything.""" + + description = 'run tests without fetching or building anything.' + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + # distutils requires this override. + pass + + def run(self): + self._add_eggs_to_path() + + import tests + loader = tests.Loader() + loader.loadTestsFromNames(['tests']) + runner = tests.Runner() + result = runner.run(loader.suite) + if not result.wasSuccessful(): + sys.exit(1) + + def _add_eggs_to_path(self): + """Adds all egg files under .eggs to sys.path""" + import pkg_resources + eggs_dir = os.path.join(PYTHON_STEM, '../../../.eggs') + eggs = [os.path.join(eggs_dir, filename) + for filename in os.listdir(eggs_dir) + if filename.endswith('.egg')] + for egg in eggs: + sys.path.insert(0, pkg_resources.normalize_path(egg)) + + class RunInterop(test.test): description = 'run interop test client/server' diff --git a/tools/run_tests/run_python.sh b/tools/run_tests/run_python.sh index beb747a616..ace49e1514 100755 --- a/tools/run_tests/run_python.sh +++ b/tools/run_tests/run_python.sh @@ -46,7 +46,7 @@ if [ "$CONFIG" = "gcov" ] then tox else - $ROOT/.tox/py27/bin/python $ROOT/setup.py test + $ROOT/.tox/py27/bin/python $ROOT/setup.py test_lite fi mkdir -p $ROOT/reports -- GitLab