[py-svn] pytest commit e90c2abaefeb: add indent facility to tracing
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat Nov 6 09:57:01 CET 2010
# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1289030717 -3600
# Node ID e90c2abaefeb33d96b672654b2698281420acc54
# Parent 09ceba1e4812bd91aecb71f2e31d78d663957f60
add indent facility to tracing
--- a/testing/test_main.py
+++ b/testing/test_main.py
@@ -553,17 +553,39 @@ class TestHookRelay:
class TestTracer:
def test_simple(self):
from pytest.main import TagTracer
- rootlogger = TagTracer()
+ rootlogger = TagTracer("[my] ")
log = rootlogger.get("pytest")
log("hello")
l = []
rootlogger.setwriter(l.append)
log("world")
assert len(l) == 1
- assert l[0] == "[pytest] world\n"
+ assert l[0] == "[my] world\n"
sublog = log.get("collection")
sublog("hello")
- assert l[1] == "[pytest:collection] hello\n"
+ assert l[1] == "[my] hello\n"
+
+ def test_indent(self):
+ from pytest.main import TagTracer
+ rootlogger = TagTracer()
+ log = rootlogger.get("1")
+ l = []
+ log.root.setwriter(lambda arg: l.append(arg))
+ log("hello")
+ log.root.indent += 1
+ log("line1")
+ log("line2")
+ log.root.indent += 1
+ log("line3")
+ log("line4")
+ log.root.indent -= 1
+ log("line5")
+ log.root.indent -= 1
+ log("last")
+ assert len(l) == 7
+ names = [x.rstrip()[len(rootlogger.prefix):] for x in l]
+ assert names == ['hello', ' line1', ' line2',
+ ' line3', ' line4', ' line5', 'last']
def test_setprocessor(self):
from pytest.main import TagTracer
--- a/pytest/main.py
+++ b/pytest/main.py
@@ -19,18 +19,21 @@ default_plugins = (
IMPORTPREFIX = "pytest_"
class TagTracer:
- def __init__(self):
+ def __init__(self, prefix="[pytest] "):
self._tag2proc = {}
self.writer = None
+ self.indent = 0
+ self.prefix = prefix
def get(self, name):
return TagTracerSub(self, (name,))
def processmessage(self, tags, args):
if self.writer is not None:
- prefix = ":".join(tags)
- content = " ".join(map(str, args))
- self.writer("[%s] %s\n" %(prefix, content))
+ if args:
+ indent = " " * self.indent
+ content = " ".join(map(str, args))
+ self.writer("%s%s%s\n" %(self.prefix, indent, content))
try:
self._tag2proc[tags](tags, args)
except KeyError:
@@ -62,7 +65,7 @@ class PluginManager(object):
self._name2plugin = {}
self._plugins = []
self._hints = []
- self.trace = TagTracer().get("pytest")
+ self.trace = TagTracer().get("pluginmanage")
if os.environ.get('PYTEST_DEBUG'):
self.trace.root.setwriter(sys.stderr.write)
self.hook = HookRelay([hookspec], pm=self)
@@ -340,6 +343,7 @@ class HookRelay:
hookspecs = [hookspecs]
self._hookspecs = []
self._pm = pm
+ self.trace = pm.trace.root.get("hook")
for hookspec in hookspecs:
self._addhooks(hookspec, prefix)
@@ -376,6 +380,7 @@ class HookCaller:
return mc.execute()
def pcall(self, plugins, **kwargs):
+ self.hookrelay.trace(self.name, kwargs)
methods = self.hookrelay._pm.listattr(self.name, plugins=plugins)
mc = MultiCall(methods, kwargs, firstresult=self.firstresult)
return mc.execute()
More information about the pytest-commit
mailing list