From cb87eeccad53c0e283173fe97d7a41d6d1322bb2 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 30 Jun 2015 16:41:35 -0500 Subject: [PATCH] Catch the traceback from get_docstring so we can output it in the correct spot --- ansible_testing/modules.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index e3c423387b5..8293c4677f2 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -14,6 +14,11 @@ from fnmatch import fnmatch from ansible.executor.module_common import REPLACER_WINDOWS from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + BLACKLIST_DIRS = frozenset(('.git',)) INDENT_REGEX = re.compile(r'(^[ \t]*)', flags=re.M) @@ -32,12 +37,18 @@ class Validator(object): """Reset the test results""" self.errors = [] self.warnings = [] + self.traces = [] @abc.abstractproperty def object_name(self): """Name of the object we validated""" pass + @abc.abstractproperty + def object_path(self): + """Path of the object we validated""" + pass + @abc.abstractmethod def validate(self, reset=True): """Run this method to generate the test results""" @@ -53,6 +64,8 @@ class Validator(object): ret = [] + for trace in self.traces: + print(trace.replace(self._root, '').lstrip('/')) for error in self.errors: print('ERROR: %s' % error) ret.append(1) @@ -299,7 +312,15 @@ class ModuleValidator(Validator): return if self._python_module(): + sys_stdout = sys.stdout + sys_stderr = sys.stderr + sys.stdout = sys.stderr = StringIO() doc, examples, ret = get_docstring(self.path) + trace = sys.stdout.getvalue() + sys.stdout = sys_stdout + sys.stderr = sys.stderr + if trace: + self.traces.append(trace) if not bool(doc): self.errors.append('Invalid or no DOCUMENTATION provided') if not bool(examples):