[svn r57565] also introduce config.maketrace(name, flush=False) which
returns either a nulltracer or opens a log in the tracedir and returns an object that you can call with args to print into the file. --HG-- branch : trunk
This commit is contained in:
@@ -226,6 +226,33 @@ class Config(object):
|
||||
if self.option.tracedir is not None:
|
||||
return py.path.local(self.option.tracedir)
|
||||
|
||||
def maketrace(self, name, flush=False):
|
||||
""" return a tracedirectory or None, depending on --tracedir. """
|
||||
tracedir = self.gettracedir()
|
||||
if tracedir is None:
|
||||
return NullTracer()
|
||||
return Tracer(tracedir.join(name), flush=flush)
|
||||
|
||||
class Tracer(object):
|
||||
file = None
|
||||
def __init__(self, path, flush=False):
|
||||
self.file = path.open(mode='w')
|
||||
self.flush = flush
|
||||
|
||||
def __call__(self, *args):
|
||||
print >>self.file, " ".join(map(str, args))
|
||||
if self.flush:
|
||||
self.file.flush()
|
||||
|
||||
def close(self):
|
||||
self.file.close()
|
||||
|
||||
class NullTracer:
|
||||
def __call__(self, *args):
|
||||
pass
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
# this is the one per-process instance of py.test configuration
|
||||
config_per_process = Config()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user