bobber6467 / python-nose

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

xunit and exceptions #469

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create the following test case :

def tests():
    print("something")
    raise IOError(42, "test")

2. launch the tests case with xunit plugin enabled (eg. "nosetests --with-xunit 
test.py)

What is the expected output? What do you see instead?
we expect the following report : 

Traceback (most recent call last):
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/users/jg/bug/test.py", line 3, in tests
    raise IOError(42, "test")
IOError: IOError: 42
-------------------- >> begin captured stdout << ---------------------
something

--------------------- >> end captured stdout << ----------------------

instead we get a stacktrace from inside nosetests code :
Traceback (most recent call last):
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/case.py", line 134, in run
    self.runTest(result)
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/case.py", line 152, in runTest
    test(result)
  File "/usr/local/afs7/lib/python3.2/unittest/case.py", line 494, in __call__
    return self.run(*args, **kwds)
  File "/usr/local/afs7/lib/python3.2/unittest/case.py", line 452, in run
    result.addError(self, exc_info)
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/proxy.py", line 134, in addError
    plugins.addError(self.test, err)
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/plugins/manager.py", line 98, in __call__
    return self.call(*arg, **kw)
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/plugins/manager.py", line 166, in simple
    result = meth(*arg, **kw)
  File "/usr/local/afs7/lib/python3.2/site-packages/nose/plugins/xunit.py", line 201, in addError
    tb = ''.join(traceback.format_exception(*err))
  File "/usr/local/afs7/lib/python3.2/traceback.py", line 180, in format_exception
    for value, tb in values:
  File "/usr/local/afs7/lib/python3.2/traceback.py", line 122, in _iter_chain
    cause = exc.__cause__
AttributeError: 'str' object has no attribute '__cause__'

What version of the product are you using? On what operating system?
python3.2, last nosetests revision

Additional details :
the error is caused by the print statement, without any output the test works 
fine.

Original issue reported on code.google.com by jean.giard@gmail.com on 14 Nov 2011 at 9:21

GoogleCodeExporter commented 8 years ago
After investigating the problem a bit further I found that it is caused by the 
Capture plugin which turns the ev of the (ec, ev, tb) tuple error into a string 
(by appending output). traceback.format_exception doesn't seem to like raw 
string values very well (or you need to disable chaining, but then you don't 
get the backtrace).

then I stumbled upon nose.proxy.ResultProxy._prepareErr which seems meant to 
turn back this string into a meaningful exception (which is then printed line 
xunit plugin). this could be useful.

Original comment by jean.giard@gmail.com on 22 Nov 2011 at 1:52

GoogleCodeExporter commented 8 years ago
I propose the attached patch which solves the problem.
(duplicate code from proxy.py:89, but didn't find a place to factorise it)

Original comment by jean.giard@gmail.com on 17 Jan 2012 at 2:48

Attachments:

GoogleCodeExporter commented 8 years ago
I've tested the patch and it seems to work, however an identical fix is 
required in the addFailure method on line 216.

Original comment by lars.hv...@gmail.com on 17 Feb 2013 at 10:07