improve PYTEST_DEBUG tracing output
by putingextra data on a new lines with additional indent
This commit is contained in:
parent
3d79e7060e
commit
725e63db66
|
@ -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
|
||||
-----------------------------------
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue