# assert 0 == 1
 +  where 0 = len(caplog.records)

- **ID:** `python/pytest-caplog-empty-handler`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

caplog fixture 默认捕获 WARNING 级别的日志；如果 logger 的 propagate=False 或日志级别为 INFO，则记录不会被捕获。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   `caplog.set_level(logging.INFO, logger='mylogger')` and ensure `logging.getLogger('mylogger').propagate = True`
   ```
2. **** (85% 成功率)
   ```
   with caplog.at_level(logging.INFO):
    myfunc()
assert 'expected' in caplog.text
   ```

## 无效尝试

- **** — If the logger has `propagate = False`, records never reach the root handler that caplog attaches to. (60% 失败率)
- **** — Loses structured logging and doesn't test the actual logging behavior. (80% 失败率)
