From 26090eabc152812ba4af602dbdab8c3b7830a01c Mon Sep 17 00:00:00 2001 From: Jeevan Opel Date: Mon, 14 Oct 2024 12:37:31 -0700 Subject: [PATCH] catch logs in test --- .../tests/logs/test_logger_provider_cache.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/opentelemetry-sdk/tests/logs/test_logger_provider_cache.py b/opentelemetry-sdk/tests/logs/test_logger_provider_cache.py index 0bb25b6104..920c667904 100644 --- a/opentelemetry-sdk/tests/logs/test_logger_provider_cache.py +++ b/opentelemetry-sdk/tests/logs/test_logger_provider_cache.py @@ -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)) @@ -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))