Skip to content

Commit

Permalink
Fix for nosetests' capture plugin to avoid timeouts crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Foster committed Jul 24, 2012
1 parent 8b3cd84 commit 6f91a10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pyon/util/capture_plugin.py
@@ -0,0 +1,33 @@
#!/usr/bin/env python

"""
Hotfix for issue with BaseExceptions in nosetests's capture plugin.
Sometimes in our testing, a gevent Timeout will cause nose to come crashing
down with an error while it's trying to format the stdout/stderr capturing
which is enabled by default. Subsequent tests in a test run will all fail.
The exact issue is because the gevent Timeout is derived from BaseException,
not Exception, which the Capture plugin tests for and converts to string. By
the time it is ready to use the error object, it expects it to be a string.
Nose thankfully will let us derive and override the existing built in Plugin
by specifying the same string name ('capture') of the plugin.
See: http://nose.readthedocs.org/en/latest/plugins/builtin.html
"""

__author__ = "Dave Foster <dfoster@asascience.com>"
__license__ = "Apache 2.0"

from nose.plugins.capture import Capture

class PyccCapture(Capture):
name = 'capture'

def addCaptureToErr(self, ev, output):
if isinstance(ev, BaseException) and not isinstance(ev, Exception):
# BaseException derived? convert to unicode string so super's method doesn't choke
ev = unicode(ev)
return super(PyccCapture, self).addCaptureToErr(ev, output)

1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -29,6 +29,7 @@
'pycc_plugin=pyon.util.pycc_plugin:PYCC',
'timer_plugin=pyon.util.timer_plugin:TestTimer',
'queueblame=pyon.util.queueblame_plugin:QueueBlame',
'capture=pyon.util.capture_plugin:PyccCapture',
'insulate=pyon.util.insulate:Insulate',
'insulateslave=pyon.util.insulate:InsulateSlave',
'gevent_profiler=pyon.util.nose_gevent_profiler:TestGeventProfiler'
Expand Down

0 comments on commit 6f91a10

Please sign in to comment.