# AssertionError: assert 'expected log' in ''

- **ID:** `python/pytest-caplog-no-output`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

logger 的级别高于消息级别，或 logging 配置了 propagate=False，导致 caplog 无法捕获记录。caplog 默认级别为 WARNING。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   def test_logs(caplog):
    caplog.set_level(logging.INFO, logger='app')
    do_work()
    assert 'expected log' in caplog.text

# app/logger.py
logger = logging.getLogger('app')
logger.propagate = True
   ```
2. **** (90% 成功率)
   ```
   def test_logs(caplog):
    caplog.set_level(logging.INFO)
    do_work()
    assert any(r.message == 'expected log' for r in caplog.records)
   ```

## 无效尝试

- **** — -s disables output capture, which actually makes caplog less likely to see logs from some handlers. (70% 失败率)
- **** — May add a handler but caplog still relies on propagation and its own level; often ineffective. (65% 失败率)
