Skip to content

Commit 23eb08b

Browse files
committed
fix: fixed unit test to use the context-manager setup for the logging setup
1 parent 484615d commit 23eb08b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

opentelemetry-sdk/tests/logs/test_handler.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,20 @@ def test_log_record_exception(self):
182182

183183
def test_log_record_recursive_exception(self):
184184
"""Exception information will be included in attributes even though it is recursive"""
185-
processor, logger = set_up_test_logging(logging.ERROR)
185+
with set_up_test_logging(logging.ERROR) as (processor, logger):
186186

187-
try:
188-
raise ZeroDivisionError(
189-
ZeroDivisionError(ZeroDivisionError("division by zero"))
190-
)
191-
except ZeroDivisionError:
192-
with self.assertLogs(level=logging.ERROR):
193-
logger.exception("Zero Division Error")
187+
try:
188+
raise ZeroDivisionError(
189+
ZeroDivisionError(ZeroDivisionError("division by zero"))
190+
)
191+
except ZeroDivisionError:
192+
with self.assertLogs(level=logging.ERROR):
193+
logger.exception("Zero Division Error")
194194

195195
log_record = processor.get_log_record(0)
196196

197197
self.assertIsNotNone(log_record)
198-
self.assertEqual(log_record.body, "Zero Division Error")
198+
self.assertIn("Zero Division Error", log_record.body)
199199
self.assertEqual(
200200
log_record.attributes[SpanAttributes.EXCEPTION_TYPE],
201201
ZeroDivisionError.__name__,

0 commit comments

Comments
 (0)