33
44import logging
55import os
6+ from importlib import reload
67from pathlib import Path
78
89import pytest
910
1011import topwrap .logger
1112
12- logger = logging .getLogger ()
13-
1413
1514class TestLogger :
1615 log_content = "logging from test_logger_using_level"
1716
1817 def test_logger_using_level (self , caplog : pytest .LogCaptureFixture ):
1918 level = "INFO"
2019 cfg_path = None
20+ logger = logging .getLogger ()
2121 topwrap .logger .configure (level , cfg_path )
22+
2223 with caplog .at_level (level ):
2324 logger .debug (self .log_content )
2425 logger .info (self .log_content )
2526 assert len (caplog .records ) == 1
2627
28+ logging .shutdown ()
29+ reload (logging )
30+ topwrap .logger .configure ("WARNING" , None )
31+
2732 def test_logger_using_default (self , caplog : pytest .LogCaptureFixture ):
2833 level = None
2934 cfg_path = None
35+ logger = logging .getLogger ()
3036 topwrap .logger .configure (level , cfg_path )
3137 with caplog .at_level (topwrap .logger .DEFAULT_LOG_LEVEL ):
3238 logger .debug (self .log_content )
3339 logger .info (self .log_content )
3440 logger .warning (self .log_content )
3541 assert len (caplog .records ) == 1
3642
43+ logging .shutdown ()
44+ reload (logging )
45+ topwrap .logger .configure ("WARNING" , None )
46+
3747 def test_logger_using_cfg (self ):
3848 level = None
3949 dir_path = Path (os .getcwd ()) / "tests" / "test_logger"
4050 cfg_path = dir_path / "logger.cfg"
4151 log_path = dir_path / "test.log"
52+ logger = logging .getLogger ()
4253 topwrap .logger .configure (level , cfg_path )
4354 logger .debug (self .log_content )
4455 logger .info (self .log_content )
@@ -49,11 +60,16 @@ def test_logger_using_cfg(self):
4960 line_count = line_count + 1
5061 assert line_count == 2
5162
63+ logging .shutdown ()
64+ reload (logging )
65+ topwrap .logger .configure ("WARNING" , None )
66+
5267 def test_logger_using_level_and_cfg (self ):
5368 level = "INFO"
5469 dir_path = Path (os .getcwd ()) / "tests" / "test_logger"
5570 cfg_path = dir_path / "logger.cfg"
5671 log_path = dir_path / "test.log"
72+ logger = logging .getLogger ()
5773 topwrap .logger .configure (level , cfg_path )
5874 logger .debug (self .log_content )
5975 logger .info (self .log_content )
@@ -62,3 +78,7 @@ def test_logger_using_level_and_cfg(self):
6278 for _ in log_file :
6379 line_count = line_count + 1
6480 assert line_count == 1
81+
82+ logging .shutdown ()
83+ reload (logging )
84+ topwrap .logger .configure ("WARNING" , None )
0 commit comments