nose-devs/nose — Issue #484: crash when raising strings (including patch)
Author: cvogt
Created: 2012-01-03 20:10:36+00:00
State: open

Fixing this bug will increase compatibility with python <=2.5

Tested in python 2.5, nose1.1.2 (installed through pip). Code looks like it still exists in 1.1.3

Reproduce code:

def test():
raise "test"

Excpected output:

\test.py:3: DeprecationWarning: raising a string exception is deprecated
raise "test"
E
======================================================================
ERROR: test.test
----------------------------------------------------------------------
Traceback (most recent call last):
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "\test.py", line 3, in test
raise "test"
test: None

----------------------------------------------------------------------
Ran 1 test in 0.004s

FAILED (errors=1)

Actual output:

\test.py:3: DeprecationWarning: raising a string exception is deprecated
raise "test"
E
======================================================================
ERROR: test.test
----------------------------------------------------------------------
Traceback (most recent call last):
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\case.py", line 133, in run
self.runTest(result)
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\case.py", line 151, in runTest
test(result)
File "e:\programs\python2.5.4\lib\unittest.py", line 281, in __call__
return self.run(*args, **kwds)
File "e:\programs\python2.5.4\lib\unittest.py", line 267, in run
result.addError(self, self._exc_info())
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\proxy.py", line 135, in addError
self.result.addError(self.test, self._prepareErr(err))
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\result.py", line 64, in addError
exc_info = self._exc_info_to_string(err)
File "e:\programs\python2.5.4\lib\site-packages\nose-1.1.2-py2.5.egg\nose\result.py", line 183, in _exc_info_to_string
if issubclass(err[0], SkipTest):
TypeError: issubclass() arg 1 must be a class

----------------------------------------------------------------------
Ran 1 test in 0.005s

FAILED (errors=1)

FIX (against 1.1.2, should be valid for 1.1.3 as well):

--- result.py 2012-01-03 21:04:53.063672600 +0100
+++ result-fixed.py 2012-01-03 20:53:56.680129600 +0100
@@ -180,7 +180,7 @@
def _exc_info_to_string(self, err, test=None):
# 2.7 skip compat
from nose.plugins.skip import SkipTest
- if issubclass(err[0], SkipTest):
+ if type(err[0]) == type and issubclass(err[0], SkipTest):
return str(err[1])
# 2.3/2.4 -- 2.4 passes test, 2.3 does not
try: