Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PyTest print STDOUT and STDERR using -s

import sys
import appprint

def test_hello():
    print("hello testing")
    print("stderr during testing", file=sys.stderr)

def test_add():
    assert appprint.add(2, 3) == 5

Using also -q makes it easier to see the printed text.

$ pytest -s -q test_stdout_stderr.py
hello testing
stderr during testing
.Adding 2 to 3
.
2 passed in 0.01 seconds