diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 9905aee86c5..a8f119fd46b 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -106,6 +106,37 @@ class TestLite(setuptools.Command): self.distribution.fetch_build_eggs(self.distribution.tests_require) +class TestPy3Only(setuptools.Command): + """Command to run tests for Python 3+ features. + + This does not include asyncio tests, which are housed in a separate + directory. + """ + + description = 'run tests for py3+ features' + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + self._add_eggs_to_path() + import tests + loader = tests.Loader() + loader.loadTestsFromNames(['tests_py3_only']) + runner = tests.Runner() + result = runner.run(loader.suite) + if not result.wasSuccessful(): + sys.exit('Test failure') + + def _add_eggs_to_path(self): + self.distribution.fetch_build_eggs(self.distribution.install_requires) + self.distribution.fetch_build_eggs(self.distribution.tests_require) + + class TestAio(setuptools.Command): """Command to run aio tests without fetching or building anything.""" diff --git a/src/python/grpcio_tests/setup.py b/src/python/grpcio_tests/setup.py index 36fbaf72e23..671f0653732 100644 --- a/src/python/grpcio_tests/setup.py +++ b/src/python/grpcio_tests/setup.py @@ -59,6 +59,7 @@ COMMAND_CLASS = { 'test_lite': commands.TestLite, 'test_gevent': commands.TestGevent, 'test_aio': commands.TestAio, + 'test_py3_only': commands.TestPy3Only, } PACKAGE_DATA = { diff --git a/src/python/grpcio_tests/tests/unit/BUILD.bazel b/src/python/grpcio_tests/tests/unit/BUILD.bazel index b2274227ced..42b99023463 100644 --- a/src/python/grpcio_tests/tests/unit/BUILD.bazel +++ b/src/python/grpcio_tests/tests/unit/BUILD.bazel @@ -40,10 +40,6 @@ GRPCIO_TESTS_UNIT = [ "_session_cache_test.py", ] -GRPCIO_PY3_ONLY_TESTS_UNIT = glob([ - "*_py3_only_test.py", -]) - py_library( name = "_tcp_proxy", srcs = ["_tcp_proxy.py"], @@ -114,23 +110,3 @@ py_library( ) for test_file_name in GRPCIO_TESTS_UNIT ] - -[ - py_test( - name = test_file_name[:-len(".py")], - size = "small", - srcs = [test_file_name], - main = test_file_name, - python_version = "PY3", - srcs_version = "PY3", - deps = [ - "resources", - "test_common", - "//src/python/grpcio/grpc:grpcio", - "//src/python/grpcio_tests/tests/testing", - "//src/python/grpcio_tests/tests/unit/framework/common", - "@six", - ], - ) - for test_file_name in GRPCIO_PY3_ONLY_TESTS_UNIT -] diff --git a/src/python/grpcio_tests/tests_py3_only/__init__.py b/src/python/grpcio_tests/tests_py3_only/__init__.py new file mode 100644 index 00000000000..6732ae8cbb5 --- /dev/null +++ b/src/python/grpcio_tests/tests_py3_only/__init__.py @@ -0,0 +1,21 @@ +# Copyright 2020 The gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import + +from tests import _loader +from tests import _runner + +Loader = _loader.Loader +Runner = _runner.Runner diff --git a/src/python/grpcio_tests/tests_py3_only/unit/BUILD.bazel b/src/python/grpcio_tests/tests_py3_only/unit/BUILD.bazel new file mode 100644 index 00000000000..81b66ddc116 --- /dev/null +++ b/src/python/grpcio_tests/tests_py3_only/unit/BUILD.bazel @@ -0,0 +1,41 @@ +# Copyright 2020 The gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package( + default_testonly = True, +) + +GRPCIO_PY3_ONLY_TESTS_UNIT = glob([ + "*_test.py", +]) + +[ + py_test( + name = test_file_name[:-len(".py")], + size = "small", + srcs = [test_file_name], + main = test_file_name, + python_version = "PY3", + srcs_version = "PY3", + deps = [ + "//src/python/grpcio/grpc:grpcio", + "//src/python/grpcio_tests/tests/testing", + "//src/python/grpcio_tests/tests/unit:resources", + "//src/python/grpcio_tests/tests/unit:test_common", + "//src/python/grpcio_tests/tests/unit/framework/common", + "@six", + ], + ) + for test_file_name in GRPCIO_PY3_ONLY_TESTS_UNIT +] diff --git a/src/python/grpcio_tests/tests_py3_only/unit/__init__.py b/src/python/grpcio_tests/tests_py3_only/unit/__init__.py new file mode 100644 index 00000000000..f4b321fc5b2 --- /dev/null +++ b/src/python/grpcio_tests/tests_py3_only/unit/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2019 The gRPC Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/src/python/grpcio_tests/tests/unit/_simple_stubs_py3_only_test.py b/src/python/grpcio_tests/tests_py3_only/unit/_simple_stubs_test.py similarity index 100% rename from src/python/grpcio_tests/tests/unit/_simple_stubs_py3_only_test.py rename to src/python/grpcio_tests/tests_py3_only/unit/_simple_stubs_test.py