[PATCH 3.26] [config] Raise in case of failure to send emails when in test mode

Denis Laxalde denis.laxalde at logilab.fr
Thu Jun 13 15:04:31 CEST 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1560431053 -7200
#      jeu. juin 13 15:04:13 2019 +0200
# Branch 3.26
# Node ID a422eeca69947f1cb79155a1d1e72106d81cafd4
# Parent  dfab9ef29538becce623631339b8a48a98c7d844
# Available At https://hg.logilab.org/review/cubicweb
#              hg pull https://hg.logilab.org/review/cubicweb -r a422eeca6994
[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.

diff --git a/cubicweb/cwconfig.py b/cubicweb/cwconfig.py
--- a/cubicweb/cwconfig.py
+++ b/cubicweb/cwconfig.py
@@ -1341,6 +1341,8 @@ the repository',
             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 @@ the repository',
                 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()



More information about the cubicweb-devel mailing list