Skip to content

Commit

Permalink
Rename test objects to avoid pytest warnings (#3823)
Browse files Browse the repository at this point in the history
This PR removes unneccesary warnings

    Fixes: #3779
  • Loading branch information
geetikabatra authored May 6, 2024
1 parent d922b76 commit 397e357
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/tests/logs/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
8 changes: 4 additions & 4 deletions opentelemetry-api/tests/trace/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/tests/trace/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ 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
with trace.use_span(self.start_span(*args, **kwargs)) as span: # type: ignore
yield span


class TestSpan(NonRecordingSpan):
class SpanTest(NonRecordingSpan):
pass


Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 397e357

Please sign in to comment.