[Twisted-Python] Re: Reactor is left dirty after calling twisted.mail.smtp.sendmail via trial

Marcin Kasperski Marcin.Kasperski at softax.com.pl
Tue Feb 26 06:26:22 EST 2008

> If I send an e-mail from a Trial testcase - using t.m.smtp.sendmail,
> the reactor is left dirty.
> Is it a bug, feature, or... how should we treat this situation? 

Feature. Email is sent asynchronously, you get deferred and can use it
(for example to acknowledge that the email has already been sent).

I bet you just need to sync with this deferred. The way to do it
is to return the deferred from the test case.

> class Test1(unittest.TestCase):
>    def test_sendmail(self):
>       return smtp.sendmail('localhost', 'foo at bar.pl', 'dotz at localhost',
>                            'this leaves reactor dirty :-(').addCallback(evenIfCallbackIsCalled)

Adding callback should have no meaning here, you need to return deferred
from test to sync with that whether the processing is complicated or simple.

At first sight it seems OK to me. Are you sure you run your tests with
trial?  Syncing with returned deferreds is trial-specific, other test
runners won't do it...

| Marcin Kasperski   | The cost of a few uncorrected non-critical
| http://mekk.waw.pl | human errors is less then the cost imposed
|                    |  by a process that tries to prevent them.
|                    |           (Booch,Martin,Newkirk)

More information about the Twisted-Python mailing list