nose-devs/nose — Issue #59: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 15: ordinal not in range(128)
Author: jpellerin
Created: 2011-12-14 15:57:20+00:00
State: open

I originally reported this issue with django-nose. They pointed me over here:

https://github.com/jbalogh/django-nose/issues/31

If I write a test like this:

self.assertContains(response, u'名')
I get a stacktrace like this:

Traceback (most recent call last):
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/case.py", line 133, in run
self.runTest(result)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/case.py", line 151, in runTest
test(result)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/django/test/testcases.py", line 264, in __call__
super(TransactionTestCase, self).__call__(result)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 300, in __call__
return self.run(*args, **kwds)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 282, in run
result.addFailure(self, self._exc_info())
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/proxy.py", line 136, in addFailure
formatted = plugins.formatFailure(self.test, err)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/plugins/manager.py", line 94, in __call__
return self.call(*arg, **kw)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/plugins/manager.py", line 136, in chain
result = meth(*arg, **kw)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/plugins/capture.py", line 86, in formatFailure
return self.formatError(test, err)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/plugins/capture.py", line 81, in formatError
return (ec, self.addCaptureToErr(ev, output), tb)
File "/Users/poswald/.virtualenvs/hats/lib/python2.6/site-packages/nose/plugins/capture.py", line 90, in addCaptureToErr
output, ln('>> end captured stdout <<')])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 15: ordinal not in range(128)

It is not able to print the unicode character. Running it in the django test runner we get the output correctly:

AssertionError: Couldn't find '名' in response
Here's my setup:

$ pip freeze | grep nose
django-nose==0.1.2
nose==1.0.0

This is on a failing test so it is trying to print out the result. Note that this seems similar to this closed issue:

http://code.google.com/p/python-nose/issues/detail?id=227

Google Code Info:
Issue #: 402
Author: paulosw...@gmail.com
Created On: 2011-03-02T15:24:29.000Z
Closed On: 2011-03-21T15:58:18.000Z