Opened 15 years ago

Closed 15 years ago

#1837 defect closed fixed (fixed)

trial -e doesn't work with pyunit test cases

Reported by: radix Owned by:
Priority: highest Milestone:
Component: trial Keywords:
Cc: Branch:
Author:

Description

More frame-trimming stuff!

radix@naota ~% cat test_crap.py
import unittest
class Foo(unittest.TestCase):
    def test_crap(self):
        1/0

radix@naota ~% trial -e test_crap.py
Running 1 tests.
test_crap
  Foo
    test_crap ... Traceback (most recent call last):
  File "/home/radix/Projects/Twisted/trunk/bin/trial", line 24, in ?
    run()
  File "/home/radix/Projects/Twisted/trunk/twisted/scripts/trial.py", line 377, in run
    test_result = trialRunner.run(suite)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 499, in run
    suite.run(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 179, in run
    TestSuite.run(self, result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 117, in run
    test(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 109, in __call__
    return self.run(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 117, in run
    test(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 109, in __call__
    return self.run(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 117, in run
    test(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 109, in __call__
    return self.run(result)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/runner.py", line 117, in run
    test(result)
  File "/usr/lib/python2.4/unittest.py", line 281, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python2.4/unittest.py", line 267, in run
    result.addError(self, self.__exc_info())
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/reporter.py", line 434, in addError
    super(TreeReporter, self).addError(*args)
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/reporter.py", line 171, in addError
    self.write(self._formatFailureTraceback(error))
  File "/home/radix/Projects/Twisted/trunk/twisted/trial/reporter.py", line 245, in _formatFailureTraceback
    fail.frames, frames = self._trimFrames(fail.frames), fail.frames
AttributeError: 'tuple' object has no attribute 'frames'
radix@naota ~%

Change History (8)

comment:1 Changed 15 years ago by radix

Keywords: review added
Priority: normalhighest
Index: twisted/trial/reporter.py
===================================================================
--- twisted/trial/reporter.py   (revision 17324)
+++ twisted/trial/reporter.py   (working copy)
@@ -168,7 +168,10 @@
     def addError(self, test, error):
         super(Reporter, self).addError(test, error)
         if self.realtime:
-            self.write(self._formatFailureTraceback(error))
+            # use the error that addError appended instead of the one
+            # that was passed to us in case it was converted from a
+            # tuple to a failure
+            self.write(self._formatFailureTraceback(self.errors[-1][1]))

     def write(self, format, *args):
         s = str(format)

comment:2 Changed 15 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: changed from Jonathan Lange to radix

REJECT! No unit test.

comment:3 Changed 15 years ago by radix

you are wise!

It doesn't handle the failure case, either.

comment:4 Changed 15 years ago by Jonathan Lange

Owner: changed from radix to Jonathan Lange

comment:5 Changed 15 years ago by Jonathan Lange

Keywords: review added
Owner: changed from Jonathan Lange to radix

Branch in trial-pyunit-realtime-1837

comment:6 Changed 15 years ago by radix

Keywords: review removed
Owner: changed from radix to Jonathan Lange

I've tried this on my codebase which uses trial and it works great. The added test looks kind of strange, given that it does nothing explicit about testing the real-timeness, but I guess it a test that errored before the change and now passes. If you can think of a way to test it explicitly then that'd be cool but I think it's mergeable now.

comment:7 Changed 15 years ago by Jonathan Lange

Resolution: fixed
Status: newclosed

(In [17727]) Allow errors from pyunit tests to be reported realtime.

  • Author: jml
  • Reviewer: radix
  • Fixes #1837

Trial would blow up when reporting failures from pyunit tests only in realtime. This branch wraps the pyunit exception info in a failure object, so the stack trimming goodness works properly.

comment:8 Changed 11 years ago by <automation>

Owner: Jonathan Lange deleted
Note: See TracTickets for help on using tickets.