-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix adjusting log level called with uninitialized logger (#263)
* Fix adjusting log level called with uninitialized logger * Add test
- Loading branch information
Showing
2 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
from pyam import logger | ||
from pyam.logger import adjust_log_level | ||
import sys | ||
|
||
from pyam.logger import logger, adjust_log_level | ||
|
||
|
||
def test_context_adjust_log_level(): | ||
assert logger().getEffectiveLevel() == 20 | ||
with adjust_log_level(): | ||
assert logger().getEffectiveLevel() == 40 | ||
assert logger().getEffectiveLevel() == 20 | ||
|
||
|
||
def test_adjusting_level_for_not_initialized_logger(): | ||
# de-initialize logger to simulate adjust_log_level called before logger | ||
pyam_logger = sys.modules['pyam.logger'] | ||
pyam_logger._LOGGER = None | ||
with adjust_log_level(): | ||
pass |