1 new changeset in pytest: http://bitbucket.org/hpk42/pytest/changeset/6247ce817d98/ changeset: 6247ce817d98 user: hpk42 date: 2011-07-14 19:11:50 summary: enhance debug tracing: print trace tags at the end of message and forget about "prefix". Always log to "pytestdebug.log" if "--debug" option is given. also move related code to pytest_helpconfig plugin. affected #: 7 files (1.8 KB)
--- a/_pytest/config.py Thu Jul 14 11:46:32 2011 -0500 +++ b/_pytest/config.py Thu Jul 14 19:11:50 2011 +0200 @@ -8,8 +8,6 @@ def pytest_cmdline_parse(pluginmanager, args): config = Config(pluginmanager) config.parse(args) - if config.option.debug: - config.trace.root.setwriter(sys.stderr.write) return config def pytest_unconfigure(config): @@ -334,6 +332,7 @@ # Note that this can only be called once per testing process. assert not hasattr(self, 'args'), ( "can only parse cmdline args at most once per Config object") + self._origargs = args self._preparse(args) self._parser.hints.extend(self.pluginmanager._hints) args = self._parser.parse_setoption(args, self.option) --- a/_pytest/core.py Thu Jul 14 11:46:32 2011 -0500 +++ b/_pytest/core.py Thu Jul 14 19:11:50 2011 +0200 @@ -16,11 +16,10 @@ "junitxml resultlog doctest").split() class TagTracer: - def __init__(self, prefix="[pytest] "): + def __init__(self): self._tag2proc = {} self.writer = None self.indent = 0 - self.prefix = prefix def get(self, name): return TagTracerSub(self, (name,)) @@ -30,7 +29,7 @@ if args: indent = " " * self.indent content = " ".join(map(str, args)) - self.writer("%s%s%s\n" %(self.prefix, indent, content)) + self.writer("%s%s [%s]\n" %(indent, content, ":".join(tags))) try: self._tag2proc[tags](tags, args) except KeyError: --- a/_pytest/helpconfig.py Thu Jul 14 11:46:32 2011 -0500 +++ b/_pytest/helpconfig.py Thu Jul 14 19:11:50 2011 +0200 @@ -1,7 +1,7 @@ """ version info, help messages, tracing configuration. """ import py import pytest -import inspect, sys +import os, inspect, sys from _pytest.core import varnames def pytest_addoption(parser): @@ -18,7 +18,29 @@ help="trace considerations of conftest.py files."), group.addoption('--debug', action="store_true", dest="debug", default=False, - help="generate and show internal debugging information.") + help="store internal tracing debug information in 'pytestdebug.log'.") + + +def pytest_cmdline_parse(__multicall__): + config = __multicall__.execute() + if config.option.debug: + path = os.path.abspath("pytestdebug.log") + f = open(path, 'w') + config._debugfile = f + f.write("versions pytest-%s, py-%s, python-%s\ncwd=%s\nargs=%s\n\n" %( + pytest.__version__, py.__version__, ".".join(map(str, sys.version_info)), + os.getcwd(), config._origargs)) + config.trace.root.setwriter(f.write) + sys.stderr.write("writing pytestdebug information to %s\n" % path) + return config + +@pytest.mark.trylast +def pytest_unconfigure(config): + if hasattr(config, '_debugfile'): + config._debugfile.close() + sys.stderr.write("wrote pytestdebug information to %s\n" % + config._debugfile.name) + config.trace.root.setwriter(None) def pytest_cmdline_main(config): --- a/testing/test_config.py Thu Jul 14 11:46:32 2011 -0500 +++ b/testing/test_config.py Thu Jul 14 19:11:50 2011 +0200 @@ -88,7 +88,7 @@ config.trace.root.setwriter(l.append) config.trace("hello") assert len(l) == 1 - assert l[0] == "[pytest] hello\n" + assert l[0] == "hello [config]\n" def test_config_getvalue_honours_conftest(self, testdir): testdir.makepyfile(conftest="x=1") --- a/testing/test_core.py Thu Jul 14 11:46:32 2011 -0500 +++ b/testing/test_core.py Thu Jul 14 19:11:50 2011 +0200 @@ -586,17 +586,17 @@ class TestTracer: def test_simple(self): from _pytest.core import TagTracer - rootlogger = TagTracer("[my] ") + rootlogger = TagTracer() log = rootlogger.get("pytest") log("hello") l = [] rootlogger.setwriter(l.append) log("world") assert len(l) == 1 - assert l[0] == "[my] world\n" + assert l[0] == "world [pytest]\n" sublog = log.get("collection") sublog("hello") - assert l[1] == "[my] hello\n" + assert l[1] == "hello [pytest:collection]\n" def test_indent(self): from _pytest.core import TagTracer @@ -616,7 +616,7 @@ log.root.indent -= 1 log("last") assert len(l) == 7 - names = [x.rstrip()[len(rootlogger.prefix):] for x in l] + names = [x[:x.rfind(' [')] for x in l] assert names == ['hello', ' line1', ' line2', ' line3', ' line4', ' line5', 'last'] --- a/testing/test_helpconfig.py Thu Jul 14 11:46:32 2011 -0500 +++ b/testing/test_helpconfig.py Thu Jul 14 19:11:50 2011 +0200 @@ -62,3 +62,17 @@ "*using*pytest*py*", "*active plugins*", ]) + +def test_debug(testdir, monkeypatch): + result = testdir.runpytest("--debug") + assert result.ret == 0 + p = testdir.tmpdir.join("pytestdebug.log") + assert "pytest_sessionstart" in p.read() + +def test_PYTEST_DEBUG(testdir, monkeypatch): + monkeypatch.setenv("PYTEST_DEBUG", "1") + result = testdir.runpytest() + assert result.ret == 0 + result.stderr.fnmatch_lines([ + "*registered*PluginManager*" + ]) --- a/testing/test_terminal.py Thu Jul 14 11:46:32 2011 -0500 +++ b/testing/test_terminal.py Thu Jul 14 19:11:50 2011 +0200 @@ -524,21 +524,6 @@ ]) assert result.ret == 0 -def test_debug(testdir, monkeypatch): - result = testdir.runpytest("--debug") - result.stderr.fnmatch_lines([ - "*pytest_sessionstart*session*", - ]) - assert result.ret == 0 - -def test_PYTEST_DEBUG(testdir, monkeypatch): - monkeypatch.setenv("PYTEST_DEBUG", "1") - result = testdir.runpytest() - assert result.ret == 0 - result.stderr.fnmatch_lines([ - "*registered*PluginManager*" - ]) - class TestGenericReporting: """ this test class can be subclassed with a different option Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn