Skip to content

Commit 6f58730

Browse files
committed
fix issue with test inheritance and linting
1 parent cfca53a commit 6f58730

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

+34-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
}
5555

5656

57-
class BaseFastAPI:
57+
class TestBaseFastAPI(TestBase):
5858
def _create_app(self):
5959
app = self._create_fastapi_app()
6060
self._instrumentor.instrument_app(
@@ -77,6 +77,15 @@ def _create_app_explicit_excluded_urls(self):
7777
)
7878
return app
7979

80+
@classmethod
81+
def setUpClass(cls):
82+
if cls is TestBaseFastAPI:
83+
raise unittest.SkipTest(
84+
f"{cls.__name__} is an abstract base class"
85+
)
86+
87+
super(TestBaseFastAPI, cls).setUpClass()
88+
8089
def setUp(self):
8190
super().setUp()
8291
self.env_patch = patch.dict(
@@ -132,7 +141,16 @@ async def _():
132141
return app
133142

134143

135-
class BaseManualFastAPI(BaseFastAPI):
144+
class TestBaseManualFastAPI(TestBaseFastAPI):
145+
146+
@classmethod
147+
def setUpClass(cls):
148+
if cls is TestBaseManualFastAPI:
149+
raise unittest.SkipTest(
150+
f"{cls.__name__} is an abstract base class"
151+
)
152+
153+
super(TestBaseManualFastAPI, cls).setUpClass()
136154

137155
def test_sub_app_fastapi_call(self):
138156
"""
@@ -177,7 +195,16 @@ def test_sub_app_fastapi_call(self):
177195
)
178196

179197

180-
class BaseAutoFastAPI(BaseFastAPI):
198+
class TestBaseAutoFastAPI(TestBaseFastAPI):
199+
200+
@classmethod
201+
def setUpClass(cls):
202+
if cls is TestBaseAutoFastAPI:
203+
raise unittest.SkipTest(
204+
f"{cls.__name__} is an abstract base class"
205+
)
206+
207+
super(TestBaseAutoFastAPI, cls).setUpClass()
181208

182209
def test_sub_app_fastapi_call(self):
183210
"""
@@ -232,7 +259,7 @@ def test_sub_app_fastapi_call(self):
232259
)
233260

234261

235-
class TestFastAPIManualInstrumentation(BaseManualFastAPI, TestBase):
262+
class TestFastAPIManualInstrumentation(TestBaseManualFastAPI, TestBase):
236263
def test_instrument_app_with_instrument(self):
237264
if not isinstance(self, TestAutoInstrumentation):
238265
self._instrumentor.instrument()
@@ -472,7 +499,7 @@ async def _():
472499
return app
473500

474501

475-
class TestFastAPIManualInstrumentationHooks(BaseManualFastAPI, TestBase):
502+
class TestFastAPIManualInstrumentationHooks(TestBaseManualFastAPI, TestBase):
476503
_server_request_hook = None
477504
_client_request_hook = None
478505
_client_response_hook = None
@@ -522,7 +549,7 @@ def client_response_hook(send_span, scope, message):
522549
)
523550

524551

525-
class TestAutoInstrumentation(BaseAutoFastAPI, TestBase):
552+
class TestAutoInstrumentation(TestBaseAutoFastAPI, TestBase):
526553
"""Test the auto-instrumented variant
527554
528555
Extending the manual instrumentation as most test cases apply
@@ -636,7 +663,7 @@ def test_sub_app_fastapi_call(self):
636663
)
637664

638665

639-
class TestAutoInstrumentationHooks(BaseAutoFastAPI, TestBase):
666+
class TestAutoInstrumentationHooks(TestBaseAutoFastAPI, TestBase):
640667
"""
641668
Test the auto-instrumented variant for request and response hooks
642669

0 commit comments

Comments
 (0)