diff options
author | John Szakmeister <john@szakmeister.net> | 2013-08-11 05:51:55 -0400 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2013-08-11 10:12:25 -0400 |
commit | a248e37ad5b20ead46583afbd2821b9d68c640c8 (patch) | |
tree | c0a4c702d7e1bcd3c410ada90e04748a5b1a5741 | |
parent | 47c8d89e601e93e0606f810d1cb75f834fd81f77 (diff) | |
download | nose-a248e37ad5b20ead46583afbd2821b9d68c640c8.tar.gz |
Fix #720: nose with detailed errors raises encoding error
In this case, the exception vector being passed in was a string that
contained encoded UTF-8 sequences. It was being converted to unicode
implicitly, which was raising a UnicodeDecodeError because some bytes
were >= 128. Make sure the exception string is converted to unicode
before trying to put the whole thing together.
Thanks to Guillaume Ayoub for the test case.
-rw-r--r-- | functional_tests/support/issue720/test.py | 6 | ||||
-rw-r--r-- | functional_tests/test_failuredetail_plugin.py | 14 | ||||
-rw-r--r-- | nose/plugins/failuredetail.py | 8 |
3 files changed, 25 insertions, 3 deletions
diff --git a/functional_tests/support/issue720/test.py b/functional_tests/support/issue720/test.py new file mode 100644 index 0000000..0a194fd --- /dev/null +++ b/functional_tests/support/issue720/test.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +import unittest +class Test(unittest.TestCase): + def test(self): + print u"Unicöde" + assert 1 == 2 diff --git a/functional_tests/test_failuredetail_plugin.py b/functional_tests/test_failuredetail_plugin.py index 284cf49..8484461 100644 --- a/functional_tests/test_failuredetail_plugin.py +++ b/functional_tests/test_failuredetail_plugin.py @@ -46,5 +46,19 @@ class TestFailureDetailWithCapture(PluginTester, unittest.TestCase): assert expect in self.output +class TestFailureDetailWithUnicodeAndCapture(PluginTester, unittest.TestCase): + activate = "-d" + args = ['-v'] + plugins = [FailureDetail(), Capture()] + suitepath = os.path.join(support, 'issue720') + + def runTest(self): + print '*' * 70 + print str(self.output) + print '*' * 70 + + assert 'UnicodeDecodeError' not in self.output + assert 'UnicodeEncodeError' not in self.output + if __name__ == '__main__': unittest.main() diff --git a/nose/plugins/failuredetail.py b/nose/plugins/failuredetail.py index 4c0729c..6462865 100644 --- a/nose/plugins/failuredetail.py +++ b/nose/plugins/failuredetail.py @@ -7,6 +7,7 @@ debugging information. """ from nose.plugins import Plugin +from nose.pyversion import exc_to_unicode, force_unicode from nose.inspector import inspect_traceback class FailureDetail(Plugin): @@ -38,10 +39,11 @@ class FailureDetail(Plugin): """Add detail from traceback inspection to error message of a failure. """ ec, ev, tb = err - tbinfo, str_ev = None, str(ev) + tbinfo, str_ev = None, exc_to_unicode(ev) + if tb: - tbinfo = inspect_traceback(tb) - str_ev = '\n'.join([str(ev), tbinfo]) + tbinfo = force_unicode(inspect_traceback(tb)) + str_ev = '\n'.join([str_ev, tbinfo]) test.tbinfo = tbinfo return (ec, str_ev, tb) |