python
runtime_error
ai_generated
true
AssertionError: assert 'Hello' in '' (captured stdout is empty)
ID: python/pytest-capture-stdout-assertion
80%Fix Rate
86%Confidence
0Evidence
2025-03-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.4.0 | active | — | — | — |
Root Cause
测试期望捕获标准输出,但被测代码未打印任何内容,或输出被重定向。
generic中文
测试期望捕获标准输出,但被测代码未打印任何内容,或输出被重定向。
Workarounds
-
90% success
确保代码中有 print 或 logging 输出,且使用 capsys 捕获。
-
95% success
在测试中调用 `out, err = capsys.readouterr()` 获取输出并断言。
Dead Ends
Common approaches that don't work:
-
70% fail
修改被测代码,且可能不满足测试意图。
-
60% fail
如果代码本身没有输出,flush 无效。