granite.io module

Provides utilities for handling I/O during test excution.

capture_output()[source]

Captures both stdout and stderr and stores into a string buffer.

Example:

import sys

with capture_output() as (stdout, stderr):
    stdout = 'This is stdout'
    stderr = 'This is stderr'

    print(stdout)
    assert stdout.getvalue() == stdout.strip()

    sys.stderr.write(stderr)
    assert stderr.getvalue() == stderr
capture_stderr()[source]

Captures stderr and stores in a string buffer.

Example:

with capture_stderr() as stderr:
    stderr = 'Hello, World!
    print(stderr)
    assert stderr.getvalue() == stderr.strip()

The yielded value is StringIO buffer. See its documentation for more details.

capture_stdout()[source]

Captures stdout and stores in a string buffer.

Example:

with capture_stdout() as stdout:
    stdout = 'Hello, World!
    print(stdout)
    assert stdout.getvalue() == stdout.strip()

The yielded value is a StringIO buffer. See its documentation for more details.