summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-06-05 13:06:33 +0200
committerPetr Viktorin <pviktori@redhat.com>2013-07-15 15:49:09 +0200
commit9cbd2327180055b79acbb37e814006f7176d2291 (patch)
tree8adccf5f578726aef8293b31fc8bda031b8965d5
parent5365e1b81bb58425b3ac9f6234f01a381ea026ac (diff)
downloadfreeipa-9cbd2327180055b79acbb37e814006f7176d2291.zip
freeipa-9cbd2327180055b79acbb37e814006f7176d2291.tar.gz
freeipa-9cbd2327180055b79acbb37e814006f7176d2291.tar.xz
Show logs in failed tests
Output from IPA's log manager is not captured by Nose's logcapture plugin. Forward IPA logs to a regular Python logger so that they are shown on failures. IPA log messages are also shown on standard error. Filter out Paramiko logs by default; these are too verbose. Part of the work for: https://fedorahosted.org/freeipa/ticket/3621
-rw-r--r--ipatests/beakerlib_plugin.py4
-rwxr-xr-xipatests/ipa-run-tests27
2 files changed, 31 insertions, 0 deletions
diff --git a/ipatests/beakerlib_plugin.py b/ipatests/beakerlib_plugin.py
index e515bbd..bd4f846 100644
--- a/ipatests/beakerlib_plugin.py
+++ b/ipatests/beakerlib_plugin.py
@@ -88,6 +88,10 @@ class BeakerLibPlugin(Plugin):
self.setup_log_handler(BeakerLibLogHandler(self.run_beakerlib_command))
def setup_log_handler(self, handler):
+ # Remove the console handler (BeakerLib will print to stderr)
+ if 'console' in log_mgr.handlers:
+ log_mgr.remove_handler('console')
+ # Configure our logger
log_mgr.configure(
{
'default_level': 'DEBUG',
diff --git a/ipatests/ipa-run-tests b/ipatests/ipa-run-tests
index fe2cca6..b58e49f 100755
--- a/ipatests/ipa-run-tests
+++ b/ipatests/ipa-run-tests
@@ -29,9 +29,11 @@ Note that any relative paths given will be based on the ipatests module's path
import sys
import os
from os import path
+import logging
import nose
+from ipapython.ipa_log_manager import log_mgr
import ipatests
from ipatests.beakerlib_plugin import BeakerLibPlugin
from ipatests.order_plugin import OrderTests
@@ -43,6 +45,7 @@ cmd = [
'--doctest-tests',
'--with-ordered-tests',
'--exclude=plugins',
+ '--logging-filter=-paramiko',
'--where', os.path.dirname(ipatests.__file__),
]
cmd += sys.argv[1:]
@@ -51,4 +54,28 @@ cmd += sys.argv[1:]
# This must be set so ipalib.api gets initialized property for tests:
os.environ['IPA_UNIT_TEST_MODE'] = 'cli_test'
+
+# Forward IPA logging to a normal Python logger. Nose's logcapture plugin
+# can't work with IPA-managed loggers
+class LogHandler(logging.Handler):
+ name = 'forwarding log handler'
+ logger = logging.getLogger('IPA')
+
+ def emit(self, record):
+ self.logger.log(record.levelno, self.format(record))
+
+if 'console' in log_mgr.handlers:
+ log_mgr.remove_handler('console')
+log_mgr.configure(
+ {
+ 'default_level': 'DEBUG',
+ 'handlers': [{'log_handler': LogHandler(),
+ 'format': '[%(name)s] %(message)s',
+ 'level': 'debug'},
+ {'level': 'info',
+ 'name': 'console',
+ 'stream': sys.stderr}]},
+ configure_state='tests')
+
+
nose.main(argv=cmd, addplugins=[BeakerLibPlugin(), OrderTests()])