Permalink
Browse files

Add StreamProxy soft link io.stdout/err to sys.stdout/err

This allows io.stdout/err to be captured during tests
  • Loading branch information...
1 parent add1bd1 commit 8d284ef93e6496f1dd968c7075727aefb12f04f5 @minrk committed Apr 24, 2011
Showing with 25 additions and 0 deletions.
  1. +25 −0 IPython/testing/globalipapp.py
@@ -28,12 +28,33 @@
# our own
from . import tools
+from IPython.utils import io
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
+class StreamProxy(io.IOStream):
+ """Proxy for sys.stdout/err. This will request the stream *at call time*
+ allowing for nose's Capture plugin's redirection of sys.stdout/err.
+
+ Parameters
+ ----------
+ name : str
+ The name of the stream. This will be requested anew at every call
+ """
+
+ def __init__(self, name):
+ self.name=name
+
+ @property
+ def stream(self):
+ return getattr(sys, self.name)
+
+ def flush(self):
+ self.stream.flush()
+
# Hack to modify the %run command so we can sync the user's namespace with the
# test globals. Once we move over to a clean magic system, this will be done
# with much less ugliness.
@@ -191,5 +212,9 @@ def start_ipython():
get_ipython = _ip.get_ipython
__builtin__._ip = _ip
__builtin__.get_ipython = get_ipython
+
+ # To avoid extra IPython messages during testing, suppress io.stdout/stderr
+ io.stdout = StreamProxy('stdout')
+ io.stderr = StreamProxy('stderr')
return _ip

0 comments on commit 8d284ef

Please sign in to comment.