unittest_for_shared_utils #55

Merged
brian merged 2 commits from unittest_for_shared_utils into main 2024-10-20 21:43:06 +02:00
Showing only changes of commit 909f8f220c - Show all commits
+38
View File
@@ -0,0 +1,38 @@
"""Definition of tests for setup_logging function."""
import logging
import os
import unittest
from shared.utils import setup_logging
class TestFunctionSetupLogging(unittest.TestCase):
"""Testing function setup_logging."""
def setUp(self):
# set log level names to test
self.env_var_name = 'LOG_LEVEL'
self.log_level_list = [
'debug',
'info',
'error',
]
self.wrong_log_level_name = 'weird_name'
def test_log_level_gets_set(self):
"""Test that function updates the logging level of the root logger."""
for log_level in self.log_level_list:
# set env var
os.environ[self.env_var_name] = log_level
# execute function
setup_logging()
# get logger
logger = logging.getLogger()
# check log level
level_number = getattr(logging, log_level.upper())
self.assertEqual(logger.getEffectiveLevel(), level_number)
if __name__ == '__main__':
unittest.main()