39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""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()
|