title: Capturing stderr using py.tests capsys
body: <p>I am trying to use <a href="http://pytest.org/latest/capture.html?highlight=capsys#accessing-captured-output-from-a-test-function" rel="noreferrer">py.tests <code>capsys</code> fixture</a> to capture the standard error stream. However, this doesn't seem to work as advertised. Given this simple test:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>Produces the following output when run with py.test 2.7.0 on Python 3.4.3:</p>
  
  <pre><code>    def test_capsys(capsys):
          print('foo')
          print('bar', file=stderr)
  
          out, err = capsys.readouterr()
          assert out == 'foo\n'
  &gt;       assert err == 'bar\n'
  E       assert '' == 'bar\n'
  E         + bar
  
  test_capsys.py:10: AssertionError
  ----------------------------- Captured stderr call -----------------------------
  bar
  </code></pre>
  
  <p>The strange thing is that py.test reports the correct contents for the error stream, but <code>capsys</code> doesn't seem to capture it. Am I doing something wrong? Is this a bug?</p>