diff --git a/CHANGELOG b/CHANGELOG index 5030113c8..104f15eac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,9 @@ Changes between 2.3.4 and 2.3.5dev - allow to specify prefixes starting with "_" when customizing python_functions test discovery. (thanks Graham Horler) +- improve PYTEST_DEBUG tracing output by puting + extra data on a new lines with additional indent + Changes between 2.3.3 and 2.3.4 ----------------------------------- diff --git a/_pytest/core.py b/_pytest/core.py index b231c1686..4166ac3c4 100644 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -24,12 +24,28 @@ class TagTracer: def get(self, name): return TagTracerSub(self, (name,)) + def format_message(self, tags, args): + if isinstance(args[-1], dict): + extra = args[-1] + args = args[:-1] + else: + extra = {} + + content = " ".join(map(str, args)) + indent = " " * self.indent + + lines = [ + "%s%s [%s]\n" %(indent, content, ":".join(tags)) + ] + + for name, value in extra.items(): + lines.append("%s %s: %s\n" % (indent, name, value)) + return lines + def processmessage(self, tags, args): - if self.writer is not None: - if args: - indent = " " * self.indent - content = " ".join(map(str, args)) - self.writer("%s%s [%s]\n" %(indent, content, ":".join(tags))) + if self.writer is not None and args: + lines = self.format_message(tags, args) + self.writer(''.join(lines)) try: self._tag2proc[tags](tags, args) except KeyError: diff --git a/testing/test_core.py b/testing/test_core.py index 405ef9811..0a18a8efc 100644 --- a/testing/test_core.py +++ b/testing/test_core.py @@ -612,6 +612,19 @@ class TestTracer: assert names == ['hello', ' line1', ' line2', ' line3', ' line4', ' line5', 'last'] + def test_readable_output_dictargs(self): + from _pytest.core import TagTracer + rootlogger = TagTracer() + + out = rootlogger.format_message(['test'], [1]) + assert out == ['1 [test]\n'] + + out2= rootlogger.format_message(['test'], ['test', {'a':1}]) + assert out2 ==[ + 'test [test]\n', + ' a: 1\n' + ] + def test_setprocessor(self): from _pytest.core import TagTracer rootlogger = TagTracer()