Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e728d72d
Commit
e728d72d
authored
May 14, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#7960: merge with 3.1.
parents
6b60fb91
fc778fd0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
Lib/test/support.py
Lib/test/support.py
+8
-8
No files found.
Lib/test/support.py
View file @
e728d72d
...
...
@@ -891,14 +891,8 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
@
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"
"""
"""Return a context manager used by captured_stdout and captured_stdin
that temporarily replaces the sys stream *stream_name* with a StringIO."""
import
io
orig_stdout
=
getattr
(
sys
,
stream_name
)
setattr
(
sys
,
stream_name
,
io
.
StringIO
())
...
...
@@ -908,6 +902,12 @@ def captured_output(stream_name):
setattr
(
sys
,
stream_name
,
orig_stdout
)
def
captured_stdout
():
"""Capture the output of sys.stdout:
with captured_stdout() as s:
print("hello")
self.assertEqual(s.getvalue(), "hello")
"""
return
captured_output
(
"stdout"
)
def
captured_stderr
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment