python
runtime_error
ai_generated
true
断言错误:assert 'Hello' in ''(捕获的 stdout 为空)
AssertionError: assert 'Hello' in '' (captured stdout is empty)
ID: python/pytest-capture-stdout-assertion
80%修复率
86%置信度
0证据数
2025-03-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
根因分析
测试期望捕获标准输出,但被测代码未打印任何内容,或输出被重定向。
English
测试期望捕获标准输出,但被测代码未打印任何内容,或输出被重定向。
解决方案
-
90% 成功率
确保代码中有 print 或 logging 输出,且使用 capsys 捕获。
-
95% 成功率
在测试中调用 `out, err = capsys.readouterr()` 获取输出并断言。
无效尝试
常见但无效的做法:
-
70% 失败
修改被测代码,且可能不满足测试意图。
-
60% 失败
如果代码本身没有输出,flush 无效。