Ticket #4501 defect closed fixed
trial's error reporting (especially --tbformat=emacs) does not like unicode exceptions
| Reported by: | marienz | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | thijs | Branch: |
branches/failure-unicode-4501
(diff, github, buildbot, log) |
| Author: | exarkun | Launchpad Bug: |
Description
If I run "trial --tbformat=emacs test_wtf.py" on the following file:
from twisted.trial import unittest
class Borkage(unittest.TestCase):
def test_borkage(self):
raise ValueError(u'\xff')
I get:
test_wtf
Borkage
test_borkage ... [ERROR]
===============================================================================
[ERROR]: test_wtf.Borkage.test_borkage
Traceback (most recent call last):
File "bin/trial", line 22, in <module>
run()
File "/home/marienz/src/twisted/twisted/scripts/trial.py", line 363, in run
test_result = trialRunner.run(suite)
File "/home/marienz/src/twisted/twisted/trial/runner.py", line 835, in run
return self._runWithoutDecoration(test)
File "/home/marienz/src/twisted/twisted/trial/runner.py", line 883, in _runWithoutDecoration
result.done()
File "/home/marienz/src/twisted/twisted/trial/reporter.py", line 636, in done
self._printErrors()
File "/home/marienz/src/twisted/twisted/trial/reporter.py", line 580, in _printErrors
self._formatFailureTraceback)
File "/home/marienz/src/twisted/twisted/trial/reporter.py", line 545, in _printResults
self._write(formatter(*(content[1:])))
File "/home/marienz/src/twisted/twisted/trial/reporter.py", line 527, in _formatFailureTraceback
result = fail.getTraceback(detail=self.tbformat, elideFrameworkCode=True)
File "/home/marienz/src/twisted/twisted/python/failure.py", line 472, in getTraceback
self.printTraceback(file=io, elideFrameworkCode=elideFrameworkCode, detail=detail)
File "/home/marienz/src/twisted/twisted/python/failure.py", line 492, in printTraceback
w("%s: %s: %s\n" % (hasFrames, self.type, self.value))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128)
This is annoying because the line raising that exception is not actually in the reported traceback. Failures after this one also don't get reported anymore.
Without --tbformat=emacs the result is much better:
test_wtf
Borkage
test_borkage ... [ERROR]
===============================================================================
[ERROR]: test_wtf.Borkage.test_borkage
Traceback (most recent call last):
File "/tmp//test_wtf.py", line 9, in test_borkage
raise ValueError(u'\xff')
exceptions.ValueError: <ValueError instance at 0x97d294c with str error:
Traceback (most recent call last):
File "/home/marienz/src/twisted/twisted/python/reflect.py", line 546, in _safeFormat
return formatter(o)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in position 0: ordinal not in range(128)
>
-------------------------------------------------------------------------------
Ran 1 tests in 0.014s
FAILED (errors=1)
The problem is that if actual application code raises a weird exception like this one and you use --tbformat=emacs it is hard to figure out where the exception came from. Making trial more robust in reporting these would be nice.
Change History
Note: See
TracTickets for help on using
tickets.
