[Twisted-Python] problems with tracebacks
This problem seems to happen from time in time.
Traceback are not printed.
Now I'm running trial on a test case and I got:
[...]
test.test_mail.TestMail.test_email_plain ... [OK]
test.test_mail.TestMail.test_sendmail_html ... [ERROR]
test.test_mail.TestMail.test_sendmail_text ... [ERROR]
===============================================================================
[ERROR]: test.test_mail.TestMail.test_sendmail_html
Failure: exceptions.IndexError: list index out of range
===============================================================================
[ERROR]: test.test_mail.TestMail.test_sendmail_text
Failure: twisted.internet.defer.TimeoutError:
On 8/4/06, Manlio Perillo
This problem seems to happen from time in time.
Traceback are not printed.
Now I'm running trial on a test case and I got:
[...] test.test_mail.TestMail.test_email_plain ... [OK] test.test_mail.TestMail.test_sendmail_html ... [ERROR] test.test_mail.TestMail.test_sendmail_text ... [ERROR]
=============================================================================== [ERROR]: test.test_mail.TestMail.test_sendmail_html
Failure: exceptions.IndexError: list index out of range
=============================================================================== [ERROR]: test.test_mail.TestMail.test_sendmail_text
Failure: twisted.internet.defer.TimeoutError:
(test_sendmail_text) still running at 3.0 secs ------------------------------------------------------------------------------- Ran 4 tests in 3.078s
FAILED (errors=2, successes=1)
Unfortunately every time I got this problem I'm unable to write a small
reproducible code. And every time the problem is caused by a simple bug in the code.
What are your test cases subclassing? What version of Twisted are you using? -- Christopher Armstrong International Man of Twistery http://radix.twistedmatrix.com/ http://twistedmatrix.com/ http://canonical.com/
Christopher Armstrong ha scritto:
On 8/4/06, *Manlio Perillo*
mailto:manlio_perillo@libero.it> wrote: This problem seems to happen from time in time.
Traceback are not printed.
Now I'm running trial on a test case and I got:
[...] test.test_mail.TestMail.test_email_plain ... [OK] test.test_mail.TestMail.test_sendmail_html ... [ERROR] test.test_mail.TestMail.test_sendmail_text ... [ERROR]
=============================================================================== [ERROR]: test.test_mail.TestMail.test_sendmail_html
Failure: exceptions.IndexError: list index out of range =============================================================================== [ERROR]: test.test_mail.TestMail.test_sendmail_text
Failure: twisted.internet.defer.TimeoutError :
(test_sendmail_text) still running at 3.0 secs ------------------------------------------------------------------------------- Ran 4 tests in 3.078s FAILED (errors=2, successes=1)
Unfortunately every time I got this problem I'm unable to write a small reproducible code. And every time the problem is caused by a simple bug in the code.
What are your test cases subclassing? What version of Twisted are you using?
I use this simple test case: class TestMail(unittest.TestCase): """Test sendmail function XXX TODO: do not use a real mail server! see twisted.mail.test.test_mail """ timeout = 10 def tearDownClass(self): # XXX TODO tearDown the resolver pass def test_senmail(self): text = u"Test" msg = mail.MIMEText(text) # ... mail.sendmail(msg) The sendmail function is: def sendmail(email): """Send an email message. """ def gotMX(mx): return smtp.sendmail(mx, from_, [to], msg) try: # some things that can fail # (and *do* fail: do I just got another email package bug?) # ... msg = flatten(email) except Exception, reason: return defer.fail(reason) mxc = getMX() return mxc.getMX(host).addCallback(lambda mx: gotMX(str(mx.name))) The problem seems to be with the try statement. When I try to print or log.err the exception, I don't get the full traceback. Thanks and regards Manlio Perillo
Jean-Paul Calderone ha scritto:
On Fri, 04 Aug 2006 23:16:00 +0200, Manlio Perillo
wrote: msg = flatten(email) except Exception, reason: return defer.fail(reason)
Here you create a Deferred with a Failure with no traceback associated with it. Try returning "defer.fail()" instead.
Ok, thanks. But this means that I cannot use defer.fail to report an exception directly. As an example if a < 0: return defer.fail(RuntimeError("must be non negative")) does not print a traceback. Regards Manlio Perillo
On Saturday 05 August 2006 12:09, Manlio Perillo wrote:
Ok, thanks. But this means that I cannot use defer.fail to report an exception directly.
As an example
if a < 0: return defer.fail(RuntimeError("must be non negative"))
does not print a traceback.
Exception instances don't contain a traceback unless they have been raised. Below are three tests that return deferreds that result in a traceback and custom error message being printed. Seems like there's probably a better way, but this has always been clear enough that I haven't looked for it. Mike. ---- """The most perverse TestCase I've ever written. Failure is an error, an error is success, and success is failure. """ from twisted.trial.unittest import TestCase from twisted.python.failure import Failure from twisted.internet.defer import Deferred, fail class FailExample(TestCase): def test_implicitTBfromDeferred(self): d = Deferred() try: raise RuntimeError("Fear of success") except: d.errback() return d def test_implicitTBfromFail(self): try: raise RuntimeError("This isn't happening") except: return fail() def test_explicitTBfromFailure(self): d = Deferred() f = None try: raise RuntimeError("Hair on fire") except: f = Failure() d.errback(f) return d
participants (4)
-
Christopher Armstrong
-
Jean-Paul Calderone
-
Manlio Perillo
-
Mike Pelletier