# AssertionError：assert 'starting' in capsys.readouterr().out
E       AssertionError：assert 'starting' in ''

- **ID:** `python/pytest-capture-log-with-caplog-and-capsys`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

该消息通过 logging 发出，而不是 print，因此 capsys 没有捕获到任何内容。日志记录通过日志处理器写入 stderr，而不是 stdout。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   def test_start(caplog):
    with caplog.at_level("INFO"):
        start()
    assert "starting" in caplog.text
   ```
2. **** (85% 成功率)
   ```
   def test_start(capsys):
    start()
    captured = capsys.readouterr()
    assert "starting" in captured.err
   ```

## 无效尝试

- **** — Nothing was written to stdout in the first place. (90% 失败率)
- **** — Same stream issue; binary vs text doesn't help. (90% 失败率)
- **** — Pollutes production code to satisfy a test. (80% 失败率)
