From 397e357dfad3e6ff42c09c74d5945dfdcad24bdd Mon Sep 17 00:00:00 2001 From: Geetika Batra Date: Mon, 6 May 2024 22:30:15 +0530 Subject: [PATCH] Rename test objects to avoid pytest warnings (#3823) This PR removes unneccesary warnings Fixes: #3779 --- CHANGELOG.md | 2 ++ opentelemetry-api/tests/logs/test_proxy.py | 8 ++++---- opentelemetry-api/tests/trace/test_globals.py | 8 ++++---- opentelemetry-api/tests/trace/test_proxy.py | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2f3e65ca8..435119f71e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Stable and experimental attributes and metrics are defined under `opentelemetry.semconv._incubating` import path. ([#3586](https://github.com/open-telemetry/opentelemetry-python/pull/3586)) +- Rename test objects to avoid pytest warnings + ([#3823] (https://github.com/open-telemetry/opentelemetry-python/pull/3823)) ## Version 1.24.0/0.45b0 (2024-03-28) diff --git a/opentelemetry-api/tests/logs/test_proxy.py b/opentelemetry-api/tests/logs/test_proxy.py index cda187cae3c..9508a66327d 100644 --- a/opentelemetry-api/tests/logs/test_proxy.py +++ b/opentelemetry-api/tests/logs/test_proxy.py @@ -28,10 +28,10 @@ def get_logger( version: typing.Optional[str] = None, schema_url: typing.Optional[str] = None, ) -> _logs.Logger: - return TestLogger(name) + return LoggerTest(name) -class TestLogger(_logs.NoOpLogger): +class LoggerTest(_logs.NoOpLogger): def emit(self, record: _logs.LogRecord) -> None: pass @@ -54,9 +54,9 @@ def test_proxy_logger(self): # logger provider now returns real instance self.assertIsInstance( - _logs.get_logger_provider().get_logger("fresh"), TestLogger + _logs.get_logger_provider().get_logger("fresh"), LoggerTest ) # references to the old provider still work but return real logger now real_logger = provider.get_logger("proxy-test") - self.assertIsInstance(real_logger, TestLogger) + self.assertIsInstance(real_logger, LoggerTest) diff --git a/opentelemetry-api/tests/trace/test_globals.py b/opentelemetry-api/tests/trace/test_globals.py index c2cc80db82e..fdb213bae93 100644 --- a/opentelemetry-api/tests/trace/test_globals.py +++ b/opentelemetry-api/tests/trace/test_globals.py @@ -7,7 +7,7 @@ from opentelemetry.trace.status import Status, StatusCode -class TestSpan(trace.NonRecordingSpan): +class SpanTest(trace.NonRecordingSpan): has_ended = False recorded_exception = None recorded_status = Status(status_code=StatusCode.UNSET) @@ -110,7 +110,7 @@ def test_use_span(self): def test_use_span_end_on_exit(self): - test_span = TestSpan(trace.INVALID_SPAN_CONTEXT) + test_span = SpanTest(trace.INVALID_SPAN_CONTEXT) with trace.use_span(test_span): pass @@ -124,7 +124,7 @@ def test_use_span_exception(self): class TestUseSpanException(Exception): pass - test_span = TestSpan(trace.INVALID_SPAN_CONTEXT) + test_span = SpanTest(trace.INVALID_SPAN_CONTEXT) exception = TestUseSpanException("test exception") with self.assertRaises(TestUseSpanException): with trace.use_span(test_span): @@ -136,7 +136,7 @@ def test_use_span_set_status(self): class TestUseSpanException(Exception): pass - test_span = TestSpan(trace.INVALID_SPAN_CONTEXT) + test_span = SpanTest(trace.INVALID_SPAN_CONTEXT) with self.assertRaises(TestUseSpanException): with trace.use_span(test_span): raise TestUseSpanException("test error") diff --git a/opentelemetry-api/tests/trace/test_proxy.py b/opentelemetry-api/tests/trace/test_proxy.py index 8c367afb6da..8c20d054913 100644 --- a/opentelemetry-api/tests/trace/test_proxy.py +++ b/opentelemetry-api/tests/trace/test_proxy.py @@ -38,7 +38,7 @@ def get_tracer( class TestTracer(trace.NoOpTracer): def start_span(self, *args, **kwargs): - return TestSpan(INVALID_SPAN_CONTEXT) + return SpanTest(INVALID_SPAN_CONTEXT) @_agnosticcontextmanager # pylint: disable=protected-access def start_as_current_span(self, *args, **kwargs): # type: ignore @@ -46,7 +46,7 @@ def start_as_current_span(self, *args, **kwargs): # type: ignore yield span -class TestSpan(NonRecordingSpan): +class SpanTest(NonRecordingSpan): pass @@ -82,7 +82,7 @@ def test_proxy_tracer(self): # reference to old proxy tracer now delegates to a real tracer and # creates real spans with tracer.start_span("") as span: - self.assertIsInstance(span, TestSpan) + self.assertIsInstance(span, SpanTest) def test_late_config(self): # get a tracer and instrument a function as we would at the @@ -100,4 +100,4 @@ def my_function() -> Span: # configure tracing provider trace.set_tracer_provider(TestProvider()) # call function again, we should now be getting a TestSpan - self.assertIsInstance(my_function(), TestSpan) + self.assertIsInstance(my_function(), SpanTest)