From d336c56d948f86f4c8c7ffa2680995f274e11677 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:45:30 +0100 Subject: [PATCH] Avoid root logger's level being changed (#28638) * avoid root logger's level being changed --------- Co-authored-by: ydshieh --- tests/trainer/test_trainer.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/trainer/test_trainer.py b/tests/trainer/test_trainer.py index d34a72b2ca..55cc35cf6a 100644 --- a/tests/trainer/test_trainer.py +++ b/tests/trainer/test_trainer.py @@ -50,6 +50,7 @@ from transformers.testing_utils import ( TOKEN, USER, CaptureLogger, + LoggingLevel, TestCasePlus, backend_device_count, execute_subprocess_async, @@ -1290,17 +1291,19 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon): else: self.assertNotIn(log_info_string, cl.out) - # test with low log_level - lower than info - with CaptureLogger(logger) as cl: - trainer = get_regression_trainer(log_level="debug") - trainer.train() - self.assertIn(log_info_string, cl.out) + with LoggingLevel(logging.INFO): + # test with low log_level - lower than info + with CaptureLogger(logger) as cl: + trainer = get_regression_trainer(log_level="debug") + trainer.train() + self.assertIn(log_info_string, cl.out) - # test with high log_level - should be quiet - with CaptureLogger(logger) as cl: - trainer = get_regression_trainer(log_level="error") - trainer.train() - self.assertNotIn(log_info_string, cl.out) + with LoggingLevel(logging.INFO): + # test with high log_level - should be quiet + with CaptureLogger(logger) as cl: + trainer = get_regression_trainer(log_level="error") + trainer.train() + self.assertNotIn(log_info_string, cl.out) def test_save_checkpoints(self): with tempfile.TemporaryDirectory() as tmpdir: