pombreda / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

failuredetail:formatFailure can't accept unicode string #415

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Put this somewhere in your unit test method

# -*- coding: utf-8 -*-
...

def testi18n(self):
    self.assertEqual(u'電郵', 'Email')

2. run nosetest

What is the expected output? What do you see instead?

Traceback (most recent call last):
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/case.py", line 133, in run
    self.runTest(result)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/case.py", line 151, in runTest
    test(result)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/unittest2/case.py", line 398, in __call__
    return self.run(*args, **kwds)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/unittest2/case.py", line 342, in run
    result.addFailure(self, sys.exc_info())
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/proxy.py", line 136, in addFailure
    formatted = plugins.formatFailure(self.test, err)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/plugins/manager.py", line 94, in __call__
    return self.call(*arg, **kw)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/plugins/manager.py", line 136, in chain
    result = meth(*arg, **kw)
  File "/Users/wyuenho/Documents/workspace/hometasty/lib/python2.6/site-packages/nose/plugins/failuredetail.py", line 43, in formatFailure
    return (ec, '\n'.join([str(ev), tbinfo]), tb)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 30-31: 
ordinal not in range(128)

What version of the product are you using? On what operating system?
nose 1.0.0, python 2.6, Mac OS X 10.6.7

Original issue reported on code.google.com by wyue...@gmail.com on 30 Apr 2011 at 6:51

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/python-nose/issues/detail?id=402 is potentially 
related (but a different tb). I have the same issue on the same line - should 
be unicode instead of str? 

Original comment by peter.lu...@gmail.com on 10 May 2011 at 8:00

GoogleCodeExporter commented 9 years ago
Without --detailed-errors I get "AssertionError: <unprintable AssertionError 
object>" which is still not useful to understand what the failure is. (also on 
nose 1.0.0 and python 2.6.3).

Original comment by peter.lu...@gmail.com on 10 May 2011 at 8:06

GoogleCodeExporter commented 9 years ago
Yep, that should not be str(), it should be repr() or something that does safe 
decoding/encoding (not unicode though).

Original comment by kumar.mcmillan on 10 May 2011 at 3:51

GoogleCodeExporter commented 9 years ago
Why not unicode?  The encoding to a byte stream should happen later, when the 
proper encoding can be known (for writing to the terminal or an xml file or 
some other log).

Original comment by rasmus...@gmail.com on 11 May 2011 at 12:09

GoogleCodeExporter commented 9 years ago
I just meant you can't call unicode(ev) because that implicitly calls 
unicode(ev, encoding=sys.getdefaultencoding()) or, on most systems, unicode(ev, 
encoding='ascii').  More info: http://farmdev.com/talks/unicode/

Original comment by kumar.mcmillan on 11 May 2011 at 4:34