Issue 7960: test.support.captured_output has invalid docstring example (original) (raw)
Issue7960
Created on 2010-02-18 21:23 by mnewman, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (5) | ||
---|---|---|
msg99529 - (view) | Author: Michael Newman (mnewman) | Date: 2010-02-18 21:23 |
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. | ||
msg99536 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2010-02-18 22:07 |
I don't see why the example wouldn't work anymore. It's just in the wrong function's docs :) | ||
msg135954 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-05-14 05:44 |
New changeset 459e2c024420 by Ezio Melotti in branch '2.7': #7960: fix docstrings for captured_output and captured_stdout. http://hg.python.org/cpython/rev/459e2c024420 New changeset c2126d89c29b by Ezio Melotti in branch '3.1': #7960: fix docstrings for captured_output and captured_stdout. http://hg.python.org/cpython/rev/c2126d89c29b New changeset 18a192ae6db9 by Ezio Melotti in branch '3.2': #7960: merge with 3.1. http://hg.python.org/cpython/rev/18a192ae6db9 New changeset 7517add4aec9 by Ezio Melotti in branch 'default': #7960: merge with 3.2. http://hg.python.org/cpython/rev/7517add4aec9 | ||
msg135955 - (view) | Author: Ezio Melotti (ezio.melotti) * ![]() |
Date: 2011-05-14 05:49 |
I fixed the docstring, however I think captured_output should be renamed _captured_output, since it only works with sys.stdout/in/err and there are already 3 other functions (in 3.2/3.3) that use captured_output to replace the 3 std* streams. There's no reason to document and use it elsewhere. Georg, what do you think? | ||
msg135969 - (view) | Author: Roundup Robot (python-dev) ![]() |
Date: 2011-05-14 11:57 |
New changeset ec35f86efb0d by Ezio Melotti in branch 'default': Merge with 3.2 and also remove captured_output from __all__ (see #7960). http://hg.python.org/cpython/rev/ec35f86efb0d |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:57 | admin | set | github: 52208 |
2011-05-14 11:59:09 | ezio.melotti | set | status: open -> closed |
2011-05-14 11:57:28 | python-dev | set | messages: + |
2011-05-14 05:49:29 | ezio.melotti | set | resolution: fixedmessages: + stage: resolved |
2011-05-14 05:44:24 | python-dev | set | nosy: + python-devmessages: + |
2010-02-18 22:07:29 | georg.brandl | set | assignee: georg.brandl -> ezio.melottimessages: + nosy: + ezio.melotti |
2010-02-18 21:23:59 | mnewman | create |