##// END OF EJS Templates
Option to spew subprocess streams during tests...
Thomas Kluyver -
Show More
@@ -43,11 +43,10 b' KC = None'
43 43 def start_new_kernel(argv=None):
44 44 """start a new kernel, and return its Manager and Client"""
45 45 km = KernelManager()
46 kwargs = dict(stdout=nose.ipy_stream_capturer.writefd, stderr=STDOUT)
46 kwargs = dict(stdout=nose.iptest_stdstreams_fileno(), stderr=STDOUT)
47 47 if argv:
48 48 kwargs['extra_arguments'] = argv
49 49 km.start_kernel(**kwargs)
50 nose.ipy_stream_capturer.ensure_started()
51 50 kc = km.client()
52 51 kc.start_channels()
53 52
@@ -37,16 +37,15 b' class TestProcessLauncher(LocalProcessLauncher):'
37 37 """subclass LocalProcessLauncher, to prevent extra sockets and threads being created on Windows"""
38 38 def start(self):
39 39 if self.state == 'before':
40 # Store stdout & stderr to show with failing tests.
41 # This is defined in IPython.testing.iptest
40 42 self.process = Popen(self.args,
41 stdout=nose.ipy_stream_capturer.writefd, stderr=STDOUT,
43 stdout=nose.iptest_stdstreams_fileno(), stderr=STDOUT,
42 44 env=os.environ,
43 45 cwd=self.work_dir
44 46 )
45 47 self.notify_start(self.process.pid)
46 48 self.poll = self.process.poll
47 # Store stdout & stderr to show with failing tests.
48 # This is defined in IPython.testing.iptest
49 nose.ipy_stream_capturer.ensure_started()
50 49 else:
51 50 s = 'The process was already started and has state: %r' % self.state
52 51 raise ProcessStateError(s)
@@ -407,14 +407,25 b' class SubprocessStreamCapturePlugin(Plugin):'
407 407 def __init__(self):
408 408 Plugin.__init__(self)
409 409 self.stream_capturer = StreamCapturer()
410 self.destination = os.environ.get('IPTEST_SUBPROC_STREAMS', 'capture')
410 411 # This is ugly, but distant parts of the test machinery need to be able
411 412 # to redirect streams, so we make the object globally accessible.
412 nose.ipy_stream_capturer = self.stream_capturer
413 nose.iptest_stdstreams_fileno = self.get_write_fileno
414
415 def get_write_fileno(self):
416 if self.destination == 'capture':
417 self.stream_capturer.ensure_started()
418 return self.stream_capturer.writefd
419 elif self.destination == 'discard':
420 return os.open(os.devnull, os.O_WRONLY)
421 else:
422 return sys.__stdout__.fileno()
413 423
414 424 def configure(self, options, config):
415 425 Plugin.configure(self, options, config)
416 426 # Override nose trying to disable plugin.
417 self.enabled = True
427 if self.destination == 'capture':
428 self.enabled = True
418 429
419 430 def startTest(self, test):
420 431 # Reset log capture
@@ -237,20 +237,23 b' def prepare_controllers(options):'
237 237 c_py = [PyTestController(name) for name in py_testgroups]
238 238
239 239 configure_py_controllers(c_py, xunit=options.xunit,
240 coverage=options.coverage, extra_args=options.extra_args)
240 coverage=options.coverage, subproc_streams=options.subproc_streams,
241 extra_args=options.extra_args)
241 242
242 243 controllers = c_py + c_js
243 244 to_run = [c for c in controllers if c.will_run]
244 245 not_run = [c for c in controllers if not c.will_run]
245 246 return to_run, not_run
246 247
247 def configure_py_controllers(controllers, xunit=False, coverage=False, extra_args=()):
248 def configure_py_controllers(controllers, xunit=False, coverage=False,
249 subproc_streams='capture', extra_args=()):
248 250 """Apply options for a collection of TestController objects."""
249 251 for controller in controllers:
250 252 if xunit:
251 253 controller.add_xunit()
252 254 if coverage:
253 255 controller.add_coverage()
256 controller.env['IPTEST_SUBPROC_STREAMS'] = subproc_streams
254 257 controller.cmd.extend(extra_args)
255 258
256 259 def do_run(controller):
@@ -469,6 +472,9 b" argparser.add_argument('--xunit', action='store_true',"
469 472 argparser.add_argument('--coverage', nargs='?', const=True, default=False,
470 473 help="Measure test coverage. Specify 'html' or "
471 474 "'xml' to get reports.")
475 argparser.add_argument('--subproc-streams', default='capture',
476 help="What to do with stdout/stderr from subprocesses. "
477 "'capture' (default), 'show' and 'discard' are the options.")
472 478
473 479 def default_options():
474 480 """Get an argparse Namespace object with the default arguments, to pass to
General Comments 0
You need to be logged in to leave comments. Login now