python config_error ai_generated true

AssertionError: assert '' in 'Some stderr output'

ID: python/pytest-capsys-stderr-not-captured

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2025-10-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    captured = capsys.readouterr()
    assert 'expected' in captured.err
  2. 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:

  1. 60% fail

    capfd captures file descriptors, which may not be what you want.

  2. 80% fail

    This doesn't affect capture.