|
15 | 15 | from typing import TYPE_CHECKING, Any |
16 | 16 |
|
17 | 17 | import pytest |
| 18 | +from _pytest.logging import LogCaptureHandler |
18 | 19 |
|
19 | 20 | from aws_lambda_powertools import Logger |
20 | 21 | from aws_lambda_powertools.logging import correlation_paths |
@@ -1556,3 +1557,24 @@ def handler(event, context): |
1556 | 1557 | # THEN we must be able to inject context |
1557 | 1558 | log = capture_logging_output(stdout) |
1558 | 1559 | assert request_id == log["correlation_id"] |
| 1560 | + |
| 1561 | + |
| 1562 | +def test_non_preconfigured_logger_with_caplog(caplog, service_name): |
| 1563 | + caplog.set_level("INFO") |
| 1564 | + logger = Logger(service=service_name) |
| 1565 | + logger.info("testing, testing...") |
| 1566 | + pytest_handler_existence = any(isinstance(item, LogCaptureHandler) for item in logger._logger.root.handlers) |
| 1567 | + |
| 1568 | + assert pytest_handler_existence is True |
| 1569 | + assert len(caplog.records) == 1 |
| 1570 | + assert caplog.records[0].message == "testing, testing..." |
| 1571 | + |
| 1572 | + |
| 1573 | +def test_child_logger_with_caplog(caplog): |
| 1574 | + caplog.set_level("INFO") |
| 1575 | + logger = Logger(child=True) |
| 1576 | + logger.info("testing, testing...") |
| 1577 | + pytest_handler_existence = any(isinstance(item, LogCaptureHandler) for item in logger._logger.root.handlers) |
| 1578 | + |
| 1579 | + assert len(caplog.records) == 1 |
| 1580 | + assert pytest_handler_existence is True |
0 commit comments