Catches/silences stdout/stderr output.
Project description
A context manager that catches/suppresses output from sys.stderr and sys.stdout.
Usage
from outputcatcher import StdErrCatcher, StdOutCatcher
# Catching stdout
with StdOutCatcher() as fakeout:
print('This is a test. you shouldn\'t see it right away.')
print('Captured stdout: {}'.format(fakeout.output))
# Catching stderr
with StdErrCatcher() as fakeerr:
print('Testing stderr output.', file=sys.stderr)
print('Captured stderr: {}'.format(fakeerr.output))
API
StdOutCatcher(escaped=False, max_length=0)
Arguments
escaped: If truthy, output is “encoded” using repr(), but without quotes. Default: False
max_length: If non-zero, final output will not exceed max_length. Once max_length is reached, further write() calls will not write to the original stream. Default: 0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
OutputCatcher-0.0.4.tar.gz
(4.4 kB
view hashes)