# 日志输出未捕获：即使使用 -s 标志，捕获的日志也不会显示在测试报告中

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

## 根因

日志在根级别配置，没有 pytest 可以捕获的处理程序，或者未使用 caplog fixture。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   def test_logging(caplog):
    with caplog.at_level(logging.DEBUG):
        function_that_logs()
    assert 'Expected log' in caplog.text
   ```
2. **** (90% 成功率)
   ```
   [pytest]
log_cli = true
log_level = DEBUG
   ```

## 无效尝试

- **** — This configures logging globally but may not integrate with pytest's capture mechanism. (70% 失败率)
- **** — Print statements are captured, but logging is not, so the problem remains. (80% 失败率)
