Commit 78c56043 authored by simonft's avatar simonft

Quiet logging in test output when not in debug mode

Also fixes a couple logging calls that caused exceptions to be
printed.
parent 9f78da7e
......@@ -73,6 +73,15 @@ class CliBaseTest(unittest.TestCase):
self.argv = sys.argv
sys.argv = [ 'monkeysign', '--no-mail' ]
if '--debug' not in self.argv:
# Save the logging handlers on the root logger to a variable
# and replace them with a NullHandler (the null handler
# prevents logging calls from trying to add a stream handler
# back). This stops output from the tested functions from
# printing to the console and cluttering things up.
self.logging_handlers = logging.getLogger().handlers
logging.getLogger().handlers = [logging.NullHandler()]
def execute(self):
'''execute the monkeysign script directly
......@@ -120,6 +129,10 @@ class CliBaseTest(unittest.TestCase):
def tearDown(self):
sys.argv = self.argv
if '--debug' not in self.argv:
# Restore the logging handlers we removed in the setup function
logging.getLogger().handlers = self.logging_handlers
@unittest.skipUnless(Mock, 'mock library missing')
class CliTestCase(CliBaseTest):
......
......@@ -475,7 +475,7 @@ configuration files are parsed by default: %s"""
# cargo-culted from caff, thanks guilhem!
src = self.keyring.get_agent_socket()
dst = self.tmpkeyring.get_agent_socket()
logger.info(_('installing symlinks for sockets from %s to %s'), (src, dst))
logger.info(_('installing symlinks for sockets from %s to %s'), src, dst)
try:
os.unlink(dst)
except OSError as e:
......@@ -775,7 +775,7 @@ expects an EmailFactory email, but will not mail if nomail is set"""
logger.warning(_("""\
not sending email to %s, as requested, here's the encrypted signed public key you can paste in your email client:
%s"""), (msg.mailto, msg.encrypted()))
%s"""), msg.mailto, msg.encrypted())
class EmailFactory:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment