[Twisted-Python] problems with tracebacks

Manlio Perillo manlio_perillo at libero.it
Fri Aug 4 15:16:00 MDT 2006


Christopher Armstrong ha scritto:
> On 8/4/06, *Manlio Perillo* <manlio_perillo at libero.it
> <mailto:manlio_perillo at 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.test_mail.TestMail
>     testMetho
>     d=test_sendmail_text> (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




More information about the Twisted-Python mailing list