[config] Raise in case of failure to send emails when in test mode 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 13 Jun 2019 15:04:13 +0200
branch3.26
changeset 12659 a422eeca6994
parent 12635 dfab9ef29538
child 12660 23e957f0f6d6
[config] Raise in case of failure to send emails when in test mode Since, for some reason, exception log messages are not visible when running tests, it's very hard to debug when sendmails() method fails during tests. So, as in some other places, let's raise the exception when in test mode.
cubicweb/cwconfig.py
--- a/cubicweb/cwconfig.py	Fri Jun 07 14:53:03 2019 +0200
+++ b/cubicweb/cwconfig.py	Thu Jun 13 15:04:13 2019 +0200
@@ -1341,6 +1341,8 @@
             except Exception as ex:
                 self.exception("can't connect to smtp server %s:%s (%s)",
                                server, port, ex)
+                if self.mode == 'test':
+                    raise
                 return False
             for msg, recipients in msgs:
                 try:
@@ -1348,6 +1350,8 @@
                 except Exception as ex:
                     self.exception("error sending mail to %s (%s)",
                                    recipients, ex)
+                    if self.mode == 'test':
+                        raise
             smtp.close()
         finally:
             SMTP_LOCK.release()