Avoid root logger's level being changed (#28638)

* avoid root logger's level being changed

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Yih-Dar
2024-01-22 14:45:30 +01:00
committed by GitHub
parent bf674153d3
commit d336c56d94

View File

@@ -50,6 +50,7 @@ from transformers.testing_utils import (
TOKEN, TOKEN,
USER, USER,
CaptureLogger, CaptureLogger,
LoggingLevel,
TestCasePlus, TestCasePlus,
backend_device_count, backend_device_count,
execute_subprocess_async, execute_subprocess_async,
@@ -1290,17 +1291,19 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
else: else:
self.assertNotIn(log_info_string, cl.out) self.assertNotIn(log_info_string, cl.out)
# test with low log_level - lower than info with LoggingLevel(logging.INFO):
with CaptureLogger(logger) as cl: # test with low log_level - lower than info
trainer = get_regression_trainer(log_level="debug") with CaptureLogger(logger) as cl:
trainer.train() trainer = get_regression_trainer(log_level="debug")
self.assertIn(log_info_string, cl.out) trainer.train()
self.assertIn(log_info_string, cl.out)
# test with high log_level - should be quiet with LoggingLevel(logging.INFO):
with CaptureLogger(logger) as cl: # test with high log_level - should be quiet
trainer = get_regression_trainer(log_level="error") with CaptureLogger(logger) as cl:
trainer.train() trainer = get_regression_trainer(log_level="error")
self.assertNotIn(log_info_string, cl.out) trainer.train()
self.assertNotIn(log_info_string, cl.out)
def test_save_checkpoints(self): def test_save_checkpoints(self):
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir: