Skip to main content

Capturepy captures the standard output and the standard error of functions, methods and any blocks of code. It is useful when testing, debugging and working with libraries. Find out more at https://github.com/GabrieleMaurina/capturepy.

Project description

capturepy

Capturepy captures the standard output and the standard error of functions, methods and any blocks of code. It is useful when testing, debugging and working with libraries.

Install

pip install output_capture

It requires python 3.8 or higher.

Usage

See the examples.py file for a complete list of examples.

This module is based on the class Capture, which can be use as a decorator, or with the 'with' statement.

Here are some examples:

Capturing output of function
from capturepy import Capture
print('Capture stdout and stderr of function using the Capture decorator.')

@Capture
def my_func(x):
	print('first')
	print('second', end='', file=sys.stderr)
	return x**2

output, result = my_func(4)
print('The captured output is:')
print(output)
print('The function returned:')
print(result)
print()
Capturing only standard error of code using "with" statement
from capturepy import Capture
print('Capture only stderr of code using the "with" statement.')

with Capture(stdout=False) as capture:
	print('first')
	print('second', end='', file=sys.stderr)
	output = capture.get()

print('The captured stderr is:')
print(output)
print()

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

capturepy-1.0.1.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

capturepy-1.0.1-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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