# AssertionError: assert '' == 'hello\n'
  +  其中 '' = capsys.readouterr().out

- **ID:** `python/pytest-capsys-not-captured`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

输出写入了日志处理器、子进程或 C 层文件描述符，这些 capsys 都无法捕获。capsys 仅捕获 Python 层的 sys.stdout/stderr 写入。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   def test_cli(capfd):
    import subprocess, sys
    subprocess.run([sys.executable, "-c", "print('hello')"])
    out, err = capfd.readouterr()
    assert out == "hello\n"
   ```
2. **** (94% 成功率)
   ```
   import logging

def test_log(caplog):
    with caplog.at_level(logging.INFO):
        logging.getLogger("app").info("hello")
    assert "hello" in caplog.text
   ```

## 无效尝试

- **** — Each call drains the buffer; repeated calls return empty strings after the first. (80% 失败率)
- **** — That disables capture entirely; the assertion still sees nothing. (70% 失败率)
