Test Overview
This test checks that only log messages at or above the WARNING level are captured during test execution. It verifies that INFO level messages are filtered out and do not appear in the captured logs.
This test checks that only log messages at or above the WARNING level are captured during test execution. It verifies that INFO level messages are filtered out and do not appear in the captured logs.
import logging import pytest def test_log_level_filtering(caplog): caplog.set_level(logging.WARNING) logging.getLogger().info("This is an info message") logging.getLogger().warning("This is a warning message") assert "This is an info message" not in caplog.text assert "This is a warning message" in caplog.text
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | caplog fixture sets log capture level to WARNING | Logging system configured to capture WARNING and above | - | PASS |
| 3 | Logger emits INFO level message: 'This is an info message' | INFO message generated but below capture level | - | PASS |
| 4 | Logger emits WARNING level message: 'This is a warning message' | WARNING message generated and captured | - | PASS |
| 5 | Assert INFO message is not in captured logs | Captured logs do not contain INFO message | assert "This is an info message" not in caplog.text | PASS |
| 6 | Assert WARNING message is in captured logs | Captured logs contain WARNING message | assert "This is a warning message" in caplog.text | PASS |