From fc04f5d9c1047a841b9d699007e01a716ddd13aa Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 22 May 2024 13:04:19 +0200 Subject: [PATCH] grpc: remove handling for pre python 3.8 import errors While at it remove pytes asyncio markers that are not needed when running tests in IsolatedAsyncioTestCase --- .../test-requirements.txt | 1 - .../tests/test_aio_client_interceptor.py | 18 +---------------- .../test_aio_client_interceptor_filter.py | 20 +------------------ .../test_aio_client_interceptor_hooks.py | 18 +---------------- .../tests/test_aio_server_interceptor.py | 19 +----------------- .../test_aio_server_interceptor_filter.py | 18 +---------------- tox.ini | 1 - 7 files changed, 5 insertions(+), 90 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/test-requirements.txt b/instrumentation/opentelemetry-instrumentation-grpc/test-requirements.txt index 56d47af0df..9303dc27c0 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/test-requirements.txt +++ b/instrumentation/opentelemetry-instrumentation-grpc/test-requirements.txt @@ -10,7 +10,6 @@ protobuf==3.20.3 py==1.11.0 py-cpuinfo==9.0.0 pytest==7.1.3 -pytest-asyncio==0.23.5 pytest-benchmark==4.0.0 tomli==2.0.1 typing_extensions==4.9.0 diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py index 21dbc44066..7ae1649149 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor.py @@ -11,24 +11,9 @@ # 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. -try: - from unittest import IsolatedAsyncioTestCase -except ImportError: - # unittest.IsolatedAsyncioTestCase was introduced in Python 3.8. It's use - # simplifies the following tests. Without it, the amount of test code - # increases significantly, with most of the additional code handling - # the asyncio set up. - from unittest import TestCase - - class IsolatedAsyncioTestCase(TestCase): - def run(self, result=None): - self.skipTest( - "This test requires Python 3.8 for unittest.IsolatedAsyncioTestCase" - ) - +from unittest import IsolatedAsyncioTestCase import grpc -import pytest import opentelemetry.instrumentation.grpc from opentelemetry import trace @@ -65,7 +50,6 @@ async def intercept_unary_unary( return await continuation(client_call_details, request) -@pytest.mark.asyncio class TestAioClientInterceptor(TestBase, IsolatedAsyncioTestCase): def setUp(self): super().setUp() diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_filter.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_filter.py index b8c408c6cf..2bd68fd492 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_filter.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_filter.py @@ -11,27 +11,10 @@ # 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. -try: - from unittest import IsolatedAsyncioTestCase -except ImportError: - # unittest.IsolatedAsyncioTestCase was introduced in Python 3.8. It's use - # simplifies the following tests. Without it, the amount of test code - # increases significantly, with most of the additional code handling - # the asyncio set up. - from unittest import TestCase - - class IsolatedAsyncioTestCase(TestCase): - def run(self, result=None): - self.skipTest( - "This test requires Python 3.8 for unittest.IsolatedAsyncioTestCase" - ) - - import os -from unittest import mock +from unittest import IsolatedAsyncioTestCase, mock import grpc -import pytest from opentelemetry.instrumentation.grpc import ( GrpcAioInstrumentorClient, @@ -50,7 +33,6 @@ def run(self, result=None): from .protobuf import test_server_pb2_grpc # pylint: disable=no-name-in-module -@pytest.mark.asyncio class TestAioClientInterceptorFiltered(TestBase, IsolatedAsyncioTestCase): def setUp(self): super().setUp() diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_hooks.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_hooks.py index fe906b26c1..3069b30ae4 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_hooks.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_client_interceptor_hooks.py @@ -11,24 +11,9 @@ # 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. -try: - from unittest import IsolatedAsyncioTestCase -except ImportError: - # unittest.IsolatedAsyncioTestCase was introduced in Python 3.8. It's use - # simplifies the following tests. Without it, the amount of test code - # increases significantly, with most of the additional code handling - # the asyncio set up. - from unittest import TestCase - - class IsolatedAsyncioTestCase(TestCase): - def run(self, result=None): - self.skipTest( - "This test requires Python 3.8 for unittest.IsolatedAsyncioTestCase" - ) - +from unittest import IsolatedAsyncioTestCase import grpc -import pytest from opentelemetry.instrumentation.grpc import GrpcAioInstrumentorClient from opentelemetry.test.test_base import TestBase @@ -54,7 +39,6 @@ def response_hook_with_exception(_span, _response): raise Exception() -@pytest.mark.asyncio class TestAioClientInterceptorWithHooks(TestBase, IsolatedAsyncioTestCase): def setUp(self): super().setUp() diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py index 7b31b085de..050f6f8d13 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py @@ -12,26 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import asyncio - -try: - from unittest import IsolatedAsyncioTestCase -except ImportError: - # unittest.IsolatedAsyncioTestCase was introduced in Python 3.8. It's use - # simplifies the following tests. Without it, the amount of test code - # increases significantly, with most of the additional code handling - # the asyncio set up. - from unittest import TestCase - - class IsolatedAsyncioTestCase(TestCase): - def run(self, result=None): - self.skipTest( - "This test requires Python 3.8 for unittest.IsolatedAsyncioTestCase" - ) - +from unittest import IsolatedAsyncioTestCase import grpc import grpc.aio -import pytest import opentelemetry.instrumentation.grpc from opentelemetry import trace @@ -97,7 +81,6 @@ async def run_with_test_server( return resp -@pytest.mark.asyncio class TestOpenTelemetryAioServerInterceptor(TestBase, IsolatedAsyncioTestCase): async def test_instrumentor(self): """Check that automatic instrumentation configures the interceptor""" diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor_filter.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor_filter.py index 837d9c7618..34b755ced8 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor_filter.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor_filter.py @@ -11,25 +11,10 @@ # 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. -try: - from unittest import IsolatedAsyncioTestCase -except ImportError: - # unittest.IsolatedAsyncioTestCase was introduced in Python 3.8. It's use - # simplifies the following tests. Without it, the amount of test code - # increases significantly, with most of the additional code handling - # the asyncio set up. - from unittest import TestCase - - class IsolatedAsyncioTestCase(TestCase): - def run(self, result=None): - self.skipTest( - "This test requires Python 3.8 for unittest.IsolatedAsyncioTestCase" - ) - +from unittest import IsolatedAsyncioTestCase import grpc import grpc.aio -import pytest from opentelemetry import trace from opentelemetry.instrumentation.grpc import ( @@ -68,7 +53,6 @@ async def run_with_test_server( return resp -@pytest.mark.asyncio class TestOpenTelemetryAioServerInterceptor(TestBase, IsolatedAsyncioTestCase): async def test_instrumentor(self): """Check that automatic instrumentation configures the interceptor""" diff --git a/tox.ini b/tox.ini index fecc9e5af7..a60aa813e7 100644 --- a/tox.ini +++ b/tox.ini @@ -374,7 +374,6 @@ deps = test: pytest-benchmark coverage: pytest coverage: pytest-cov - grpc: pytest-asyncio ; FIXME: add coverage testing ; FIXME: add mypy testing