From 0db6fb9ec51f7cd1b4fc29a5e1a13cd3fe7657e1 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 26 Jun 2013 17:39:11 +0200 Subject: BeakerLib plugin: Log http links in test docstrings The main case for this is having ticket numbers in the Beaker ouput. --- ipatests/beakerlib_plugin.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ipatests/beakerlib_plugin.py b/ipatests/beakerlib_plugin.py index 7c27c1650..97fd2c788 100644 --- a/ipatests/beakerlib_plugin.py +++ b/ipatests/beakerlib_plugin.py @@ -24,6 +24,7 @@ import subprocess import traceback import logging import tempfile +import re import nose from nose.plugins import Plugin @@ -31,6 +32,8 @@ from nose.plugins import Plugin from ipapython import ipautil from ipapython.ipa_log_manager import log_mgr +LINK_RE = re.compile(r'https?://[^\s]+') + class BeakerLibLogHandler(logging.Handler): def __init__(self, beakerlib_command): @@ -107,6 +110,10 @@ class BeakerLibPlugin(Plugin): self.bash.stdin.flush() assert self.bash.returncode is None, "BeakerLib Bash process exited" + def log_links(self, docstring): + for match in LINK_RE.finditer(docstring or ''): + self.log.info('Link: %s', match.group()) + def report(self, stream): """End the Bash process""" self.run_beakerlib_command(['exit']) @@ -129,6 +136,7 @@ class BeakerLibPlugin(Plugin): context.__name__, caption) self.run_beakerlib_command(['rlPhaseStart', 'FAIL', phase_name]) self._in_class_setup = True + self.log_links(docstring) def stopContext(self, context): """End a test context""" @@ -148,6 +156,11 @@ class BeakerLibPlugin(Plugin): phase_name = "%s: %s" % (test.id().replace('.', '-'), caption) self.run_beakerlib_command(['rlPhaseStart', 'FAIL', phase_name]) + while hasattr(test, 'test'): + # Un-wrap Nose test cases to get at the actual test method + test = test.test + self.log_links(getattr(test, '__doc__', '')) + def stopTest(self, test): """End a test phase""" self.collect_logs(test.context) -- cgit