Message99529
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. |
|
Date |
User |
Action |
Args |
2010-02-18 21:24:01 | mnewman | set | recipients:
+ mnewman, georg.brandl |
2010-02-18 21:24:01 | mnewman | set | messageid: <1266528241.14.0.253850913596.issue7960@psf.upfronthosting.co.za> |
2010-02-18 21:23:59 | mnewman | link | issue7960 messages |
2010-02-18 21:23:59 | mnewman | create | |
|