# AssertionError: assert 'expected message' in []
# caplog.records 为空

- **ID:** `python/pytest-caplog-not-propagating`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

logger 的 propagate 标志为 False，或代码使用了 propagate=False 的自定义 handler 配置的 logger，记录无法到达 caplog 所附加的根 logger。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   def test_logs(caplog):
    logging.getLogger('mypkg').propagate = True
    with caplog.at_level(logging.INFO, logger='mypkg'):
        mypkg.do_work()
    assert 'expected message' in caplog.text
   ```
2. **** (85% 成功率)
   ```
   def test_logs(caplog):
    logger = logging.getLogger('mypkg')
    logger.addHandler(caplog.handler)
    mypkg.do_work()
    assert 'expected message' in caplog.text
   ```

## 无效尝试

- **** — Adjusts the level but does not change propagate; the record still never reaches caplog's handler. (70% 失败率)
- **** — Adds a root handler but does not affect the child logger's propagate=False setting. (80% 失败率)
