New submission from Michael Newman <michael.b.new...@gmail.com>:

test.support.captured_output is not covered in the online documents:
http://docs.python.org/3.1/library/test.html
http://docs.python.org/dev/py3k/library/test.html

However, it does have a docstring in "C:\Python31\Lib\test\support.py" (see 
below). The current example for "captured_output" does not work. Looks like 
someone moved it from "captured_stdout" but did not fully update it. Note the 
old example still references "captured_stdout". 

# Here's the current code in "support.py":

@contextlib.contextmanager
def captured_output(stream_name):
    """Run the 'with' statement body using a StringIO object in place of a
    specific attribute on the sys module.
    Example use (with 'stream_name=stdout')::

       with captured_stdout() as s:
           print("hello")
       assert s.getvalue() == "hello"
    """
    import io
    orig_stdout = getattr(sys, stream_name)
    setattr(sys, stream_name, io.StringIO())
    try:
        yield getattr(sys, stream_name)
    finally:
        setattr(sys, stream_name, orig_stdout)

def captured_stdout():
    return captured_output("stdout")

# Example for captured_output should now be:

       with captured_output("stdout") as s:
           print("hello")
       assert s.getvalue() == "hello"

# It would be nice to reconcile the online doc versus the docstrings, since it 
confusing and makes me confused whether captured_stdout is deprecated.

----------
assignee: georg.brandl
components: Documentation
messages: 99529
nosy: georg.brandl, mnewman
severity: normal
status: open
title: test.support.captured_output has invalid docstring example
versions: Python 3.1, Python 3.2

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7960>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to