Skip to main content

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(safe=False, maxlength=0) as fakeout:
    print('This is a test. you shouldn\'t see it right away.')
print('Captured stdout: {}'.format(fakeout.output))

# Catching stderr
with StdErrCatcher(safe=False, maxlength=0) as fakeerr:
    print('Testing stderr output.', file=sys.stderr)
print('Captured stderr: {}'.format(fakeerr.output))

API

StdOutCatcher(safe=False, maxlength=0)

Arguments

  • safe: If truthy, output is “encoded” using repr(). Default: False

  • maxlength: If non-zero, trim each write() call to maxlength. 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.2.tar.gz (3.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page