python
config_error
ai_generated
true
AssertionError: assert '' in 'Some stderr output'
ID: python/pytest-capsys-stderr-not-captured
80%Fix Rate
84%Confidence
0Evidence
2025-10-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The capsys fixture captures stdout but not stderr by default, or the test is using print to stderr incorrectly.
generic中文
capsys fixture 默认捕获 stdout 但不捕获 stderr,或者测试错误地使用了 print 到 stderr。
Workarounds
-
95% success
captured = capsys.readouterr() assert 'expected' in captured.err
-
90% success
def test_foo(capfd): print('stderr', file=sys.stderr) captured = capfd.readouterr() assert 'stderr' in captured.err
Dead Ends
Common approaches that don't work:
-
60% fail
capfd captures file descriptors, which may not be what you want.
-
80% fail
This doesn't affect capture.