britodfbr

Python: Accessing captured output from a test function

Jan 10th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. '''
  2. http://pytest.org/2.2.4/capture.html
  3. '''
  4. def test_myoutput(capsys): # or use "capfd" for fd-level
  5.     print ("hello")
  6.     sys.stderr.write("world\n")
  7.     out, err = capsys.readouterr()
  8.     assert out == "hello\n"
  9.     assert err == "world\n"
  10.     print "next"
  11.     out, err = capsys.readouterr()
  12.     assert out == "next\n"
Advertisement
Add Comment
Please, Sign In to add comment