Skip to content

Commit

Permalink
catch logs in test
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jopel committed Oct 14, 2024
1 parent 5a5538c commit 26090ea
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions opentelemetry-sdk/tests/logs/test_logger_provider_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def test_get_logger_single_handler(self):
# Ensure logger is lazily cached
self.assertEqual(0, len(logger_cache))

logger.warning("test message")
with self.assertLogs(level=logging.WARNING):
logger.warning("test message")

self.assertEqual(1, len(logger_cache))

# Ensure only one logger is cached
rounds = 100
for _ in range(rounds):
logger.warning("test message")
with self.assertLogs(level=logging.WARNING):
rounds = 100
for _ in range(rounds):
logger.warning("test message")

self.assertEqual(1, len(logger_cache))

Expand All @@ -56,15 +58,17 @@ def test_get_logger_multiple_loggers(self):
# Ensure loggers are lazily cached
self.assertEqual(0, len(logger_cache))

for logger in loggers:
logger.warning("test message")
with self.assertLogs(level=logging.WARNING):
for logger in loggers:
logger.warning("test message")

self.assertEqual(num_loggers, len(logger_cache))

rounds = 100
for _ in range(rounds):
for logger in loggers:
logger.warning("test message")
with self.assertLogs(level=logging.WARNING):
rounds = 100
for _ in range(rounds):
for logger in loggers:
logger.warning("test message")

self.assertEqual(num_loggers, len(logger_cache))

Expand Down

0 comments on commit 26090ea

Please sign in to comment.