Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for nosetests' capture plugin to avoid timeouts crashing
- Loading branch information
Dave Foster
committed
Jul 24, 2012
1 parent
8b3cd84
commit 6f91a10
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters