title: Writing a pytest function for checking the output on console (stdout)
body: <p><a href="http://pytest.org/capture.html" rel="noreferrer">This link</a> gives a description how to use pytest for capturing console outputs.
  I tried on this following simple code, but I get error</p>
  <pre><code>import sys
  import pytest
  def f(name):
      print &quot;hello &quot;+ name
  
  def test_add(capsys):
      f(&quot;Tom&quot;)
      out,err=capsys.readouterr()
      assert out==&quot;hello Tom&quot;
  
  
  test_add(sys.stdout)
  </code></pre>
  <p>Output:</p>
  <pre><code>python test_pytest.py 
  hello Tom
  Traceback (most recent call last):
    File &quot;test_pytest.py&quot;, line 12, in &lt;module&gt;
      test_add(sys.stdout)
    File &quot;test_pytest.py&quot;, line 8, in test_add
      out,err=capsys.readouterr()
  AttributeError: 'file' object has no attribute 'readouterr'
  </code></pre>
  <p>what is wrong and what fix needed? thank you</p>
  <p>EDIT:
  As per the comment, I changed <code>capfd</code>, but I still get the same error</p>
  <pre><code>import sys
  import pytest
  def f(name):
      print &quot;hello &quot;+ name
  
  def test_add(capfd):
      f(&quot;Tom&quot;)
      out,err=capfd.readouterr()
      assert out==&quot;hello Tom&quot;
  
  
  test_add(sys.stdout)
  </code></pre>