python
config_error
ai_generated
true
断言错误:断言 '' 在 'Some stderr output' 中
AssertionError: assert '' in 'Some stderr output'
ID: python/pytest-capsys-stderr-not-captured
80%修复率
84%置信度
0证据数
2025-10-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
capsys fixture 默认捕获 stdout 但不捕获 stderr,或者测试错误地使用了 print 到 stderr。
English
The capsys fixture captures stdout but not stderr by default, or the test is using print to stderr incorrectly.
解决方案
-
95% 成功率
captured = capsys.readouterr() assert 'expected' in captured.err
-
90% 成功率
def test_foo(capfd): print('stderr', file=sys.stderr) captured = capfd.readouterr() assert 'stderr' in captured.err
无效尝试
常见但无效的做法:
-
60% 失败
capfd captures file descriptors, which may not be what you want.
-
80% 失败
This doesn't affect capture.