Repository navigation
Description
Migrated from Launchpad: https://bugs.launchpad.net/bugs/1097975
Original Reporter: Oliver Drake
Date Created: 2013-01-09 22:56:14.406303+00:00
Status on Launchpad: Triaged
Importance: Wishlist
I was trying to play with subunit in ipython notebook:
import unittest
class MyTest(unittest.TestCase):
def test_one(self):
assert True
def test_two(self):
assert False, "two failed..."
suite1 = unittest.TestLoader().loadTestsFromTestCase(MyTest)
import subunit
import sys
test_result = subunit.TestProtocolClient(sys.stdout)
suite1.run(test_result)
The traceback I get is:
Traceback (most recent call last):
File "", line 6, in
suite1.run(test_result)
File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
test(result)
File "/usr/lib/python2.7/unittest/case.py", line 391, in call
return self.run(*args, **kwds)
File "/usr/lib/python2.7/unittest/case.py", line 331, in run
result.addFailure(self, sys.exc_info())
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/subunit/init.py", line 668, in addFailure
self._addOutcome("failure", test, error=error, details=details)
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/subunit/init.py", line 697, in _addOutcome
tb_content = TracebackContent(error, test)
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/testtools/content.py", line 142, in init
value = self._exc_info_to_unicode(err, test)
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/testtools/content.py", line 169, in _exc_info_to_unicode
msgLines = format_exception(exctype, value, tb, length)
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/testtools/compat.py", line 352, in _format_exc_info
if evalue is None:
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/testtools/compat.py", line 289, in _get_source_encoding
newtuple = _EncodingTuple(linecache.cache[filename])
File "/home/drakeol/virtualenvs/dvvtools/local/lib/python2.7/site-packages/testtools/compat.py", line 261, in _detect_encoding
# Source starting with UTF-8 BOM is either UTF-8 or a SyntaxError
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
When I run the same code in a normal python file (utf-8 encoding) it runs fine and I see subunit output on stdout:
$ python subunitscratch.py
test: main.MyTest.test_one
successful: main.MyTest.test_one
test: main.MyTest.test_two
failure: main.MyTest.test_two [
Traceback (most recent call last):
File "subunitscratch.py", line 8, in test_two
assert False, "two failed..."
AssertionError: two failed...
]
I'm guessing it's to do with the fact that running in ipython notebook means there's no encoding for the source file of a traceback...
Python 2.7.3
testrepository==0.0.8
testtools==0.9.22
nose-subunit==0.2
python-subunit==0.0.8
Aside: when I run the same code in the vanilla interpreter it runs ok but the traceback is less informative as there's no source file (expected):
suite.run(test_result)
test: main.MyTest.test_one
failure: main.MyTest.test_one [
Traceback (most recent call last):
File "", line 3, in test_one
AssertionError
]
Activity