devtools/testlib.py
changeset 6401 d7f5d873e1b8
parent 6370 8c3d6f739fa3
parent 6398 ea26eb5fd388
child 6404 2013ef8f56e9
--- a/devtools/testlib.py	Wed Oct 06 11:57:21 2010 +0200
+++ b/devtools/testlib.py	Wed Oct 06 14:04:26 2010 +0200
@@ -45,6 +45,7 @@
 from cubicweb.sobjects import notification
 from cubicweb.web import Redirect, application
 from cubicweb.server.session import security_enabled
+from cubicweb.server.hook import SendMailOp
 from cubicweb.devtools import SYSTEM_ENTITIES, SYSTEM_RELATIONS, VIEW_VALIDATORS
 from cubicweb.devtools import BASE_URL, fake, htmlparser
 from cubicweb.utils import json
@@ -291,6 +292,9 @@
     # default test setup and teardown #########################################
 
     def setUp(self):
+        # monkey patch send mail operation so emails are sent synchronously
+        self._old_mail_commit_event = SendMailOp.commit_event
+        SendMailOp.commit_event = SendMailOp.sendmails
         pause_tracing()
         previous_failure = self.__class__.__dict__.get('_repo_init_failed')
         if previous_failure is not None:
@@ -312,6 +316,7 @@
         for cnx in self._cnxs:
             if not cnx._closed:
                 cnx.close()
+        SendMailOp.commit_event = self._old_mail_commit_event
 
     def setup_database(self):
         """add your database setup code by overriding this method"""