Pytest capture STDOUT and STDERR with capsys


Captures everything that is printed to STDOUT and STDERR so we can compare that to the expected output and error.


examples/pytest/test_greet.py
from greet import welcome

def test_myoutput(capsys):
    welcome("hello", "world")
    out, err = capsys.readouterr()
    assert out == "STDOUT: hello\n"
    assert err == "STDERR: world\n"

    welcome("next")
    out, err = capsys.readouterr()
    assert out == "STDOUT: next\n"
    assert err == ""

pytest test_greet.py