diff --git a/tests/test_utils_logcfg.py b/tests/test_utils_logcfg.py index 401609265..ccd4a3df6 100644 --- a/tests/test_utils_logcfg.py +++ b/tests/test_utils_logcfg.py @@ -19,9 +19,8 @@ def setup_custom_levels(): # Add custom levels add_log_Level(log, "LONG", logging.INFO + 5, func_name="long", color="cyan") add_log_Level(log, "ENLARGE", logging.INFO + 6, func_name="enlarge", color="green") - add_log_Level(log, "TRACE", logging.DEBUG - 1, func_name="trace", color="magenta") - logcfg("TRACE") # Enable all levels >= TRACE + logcfg("LONG") # Enable all levels >= LONG # Test: add_log_Level() @pytest.mark.parametrize("levelname, logfunc, message, ansi_color", [ @@ -31,6 +30,7 @@ def setup_custom_levels(): def test_custom_levels_are_logged(levelname, logfunc, message, ansi_color, capsys): # Call the custom log function logfunc(message) + logzero.setup_default_logger(disable_colors=False) # Capture stderr where logzero outputs messages captured = capsys.readouterr().err @@ -41,31 +41,27 @@ def test_custom_levels_are_logged(levelname, logfunc, message, ansi_color, capsy assert captured.strip().endswith(ANSI_RESET), "Missing ANSI reset code at end of log line" # Test: setup_import_logging() -def test_import_logging_multiple_modules(capfd): +def test_import_logging_multiple_modules(capfd): + add_log_Level(log, "TRACE", logging.DEBUG - 1, func_name="trace") + logcfg("TRACE") setup_import_logging() - # Perform imports import json import math import io - import json # Duplicate - import math # Duplicate import random - import random # Duplicate + import json # duplicate + import math # duplicate + import random # duplicate - # Capture stdout/stderr output out, err = capfd.readouterr() - # Expected modules to be logged once expected_imports = {"json", "math", "io", "random"} for mod in expected_imports: - assert f"importing: {mod}" in out, f"Missing import log for {mod}" + assert f"importing: {mod}" in err, f"Missing import log for {mod}" - # Check duplicates only logged once - assert out.count("importing: json") == 1 - assert out.count("importing: math") == 1 - assert out.count("importing: random") == 1 + assert err.count("importing: json") == 1 + assert err.count("importing: math") == 1 + assert err.count("importing: random") == 1 - # Check custom TRACE level is used - assert "TRACE" in out.upper()