@@ -81,18 +81,24 @@ def setup(self):
8181 """
8282 pass
8383
84- def launch (self , buffer_output = False ):
84+ def launch (self , buffer_output = False , capture_output = False ):
8585 # print('*** ENV:', self.env) # dbg
8686 # print('*** CMD:', self.cmd) # dbg
8787 env = os .environ .copy ()
8888 env .update (self .env )
89- output = subprocess .PIPE if buffer_output else None
90- stdout = subprocess .STDOUT if buffer_output else None
91- self .process = subprocess .Popen (self .cmd , stdout = output ,
92- stderr = stdout , env = env )
89+ if buffer_output :
90+ capture_output = True
91+ self .stdout_capturer = c = StreamCapturer (echo = not buffer_output )
92+ c .start ()
93+ stdout = c .writefd if capture_output else None
94+ stderr = subprocess .STDOUT if capture_output else None
95+ self .process = subprocess .Popen (self .cmd , stdout = stdout ,
96+ stderr = stderr , env = env )
9397
9498 def wait (self ):
95- self .stdout , _ = self .process .communicate ()
99+ self .process .wait ()
100+ self .stdout_capturer .halt ()
101+ self .stdout = self .stdout_capturer .get_buffer ()
96102 return self .process .returncode
97103
98104 def print_extra_info (self ):
@@ -224,7 +230,6 @@ class JSController(TestController):
224230
225231 requirements = ['zmq' , 'tornado' , 'jinja2' , 'casperjs' , 'sqlite3' ,
226232 'jsonschema' ]
227- display_slimer_output = False
228233
229234 def __init__ (self , section , xunit = True , engine = 'phantomjs' , url = None ):
230235 """Create new test runner."""
@@ -279,8 +284,7 @@ def launch(self, buffer_output):
279284 # If the engine is SlimerJS, we need to buffer the output because
280285 # SlimerJS does not support exit codes, so CasperJS always returns 0.
281286 if self .engine == 'slimerjs' and not buffer_output :
282- self .display_slimer_output = True
283- return super (JSController , self ).launch (buffer_output = True )
287+ return super (JSController , self ).launch (capture_output = True )
284288
285289 else :
286290 return super (JSController , self ).launch (buffer_output = buffer_output )
@@ -292,8 +296,6 @@ def wait(self, *pargs, **kwargs):
292296 # errors. Otherwise, just return the return code.
293297 if self .engine == 'slimerjs' :
294298 stdout = bytes_to_str (self .stdout )
295- if self .display_slimer_output :
296- print (stdout )
297299 if ret != 0 :
298300 # This could still happen e.g. if it's stopped by SIGINT
299301 return ret
0 commit comments