I am trying to use py.tests capsys fixture to capture the standard error stream. However, this doesn't seem to work as advertised. Given this simple test:
from sys import stderr def test_capsys(capsys): print('foo') print('bar', file=stderr) out, err = capsys.readouterr() assert out == 'foo\n' assert err == 'bar\n' Produces the following output when run with py.test 2.7.0 on Python 3.4.3:
def test_capsys(capsys): print('foo') print('bar', file=stderr) out, err = capsys.readouterr() assert out == 'foo\n' > assert err == 'bar\n' E assert '' == 'bar\n' E + bar test_capsys.py:10: AssertionError ----------------------------- Captured stderr call ----------------------------- bar The strange thing is that py.test reports the correct contents for the error stream, but capsys doesn't seem to capture it. Am I doing something wrong? Is this a bug?