Skip to content

Commit

Permalink
caplog un-disable logging, add missing test coverage
Browse files Browse the repository at this point in the history
- Adds test coverage for `force_enable_logging` with a string `level`. Fixes [code coverage check](https://github.com/pytest-dev/pytest/pull/8758/checks?check_run_id=4123920877)

Issue: pytest-dev#8711
PR: pytest-dev#8758
  • Loading branch information
alexlambson committed Nov 11, 2021
1 parent fe822d9 commit 377d826
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions testing/logging/test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ def test_with_statement_logging_disabled(caplog, cleanup_disabled_logging):
assert logging.root.manager.disable == logging.CRITICAL


@pytest.mark.parametrize(
"level_str,expected_disable_level",
[
("CRITICAL", logging.ERROR),
("ERROR", logging.WARNING),
("WARNING", logging.INFO),
("INFO", logging.DEBUG),
("DEBUG", logging.NOTSET),
("NOTSET", logging.NOTSET),
("NOTVALIDLEVEL", logging.NOTSET),
],
)
def test_force_enable_logging_level_string(
caplog, cleanup_disabled_logging, level_str, expected_disable_level
):
"""Test force enabling logging using a level string.
The disabled log level always needs to be one level lower than the level
that we want caplog to catch, so the expected level will be one below the desired level string.
"""
test_logger = logging.getLogger("test_str_level_force_enable")
# Emulate a testing environment where all logging is disabled.
logging.disable(logging.CRITICAL)
# Make sure all logging was disabled.
assert not test_logger.isEnabledFor(logging.CRITICAL)
caplog.force_enable_logging(level_str, test_logger)
# Make sure that the disabled level is now one below the requested logging level.
assert test_logger.manager.disable == expected_disable_level


def test_log_access(caplog):
caplog.set_level(logging.INFO)
logger.info("boo %s", "arg")
Expand Down

0 comments on commit 377d826

Please sign in to comment.