human
Complete this python program:
def capture_stdout(f):
assistant
#Here is the Python code you requested.

    """Decorator to capture stdout in a buffer so that it can be checked
    (or suppressed) during testing.
    Parameters
    f : callable
    The test that is capturing stdout.
    Returns
    f : callable
    The decorated test ``f``, which captures stdout.
    Examples
    >>> from pandas.util.testing import capture_stdout
    >>> import sys
    >>> @capture_stdout
    ... def test_print_pass():
    ...     print("foo")
    ...     out = sys.stdout.getvalue()
    ...     assert out == "foo
    >>> @capture_stdout
    ... def test_print_fail():
    ...     print("foo")
    ...     out = sys.stdout.getvalue()
    ...     assert out == "bar
    AssertionError: assert \foo
    \ == \bar
    """
    @wraps(f)
    def wrapper(*args, **kwargs):
        try:
            sys.stdout = StringIO()
            f(*args, **kwargs)
        finally:
            sys.stdout = sys.__stdout__
    return wrapper