Complete the code to capture only WARNING level logs in pytest.
def test_warning_logs(caplog): import logging with caplog.at_level([1]): logging.warning("Warning message") assert "Warning message" in caplog.text
Use logging.WARNING to capture warning level logs.
Complete the code to assert that no ERROR logs are captured.
def test_no_error_logs(caplog): import logging with caplog.at_level(logging.INFO): logging.info("Info message") assert not any(record.levelname == [1] for record in caplog.records)
We check that no log record has level name "ERROR".
Fix the error in the code to capture only ERROR logs.
def test_error_logs(caplog): import logging with caplog.at_level([1]): logging.error("Error occurred") assert "Error occurred" in caplog.text
Use logging.ERROR to capture error level logs.
Fill both blanks to capture only DEBUG logs and assert their presence.
def test_debug_logs(caplog): import logging with caplog.at_level([1]): logging.debug("Debug info") assert any(record.levelname == [2] for record in caplog.records)
logging.INFO instead of logging.DEBUG.Use logging.DEBUG to capture debug logs and check for level name "DEBUG".
Fill all three blanks to filter WARNING logs, log a warning, and assert its presence by level name.
def test_warning_level_filter(caplog): import logging with caplog.at_level([1]): logging.[2]("Warning issued") assert any(record.levelname == [3] for record in caplog.records)
logging.error or logging.WARNING as method name.Set level to logging.WARNING, log with logging.warning, and check for level name "WARNING".
