parent
0dbe04abcb
commit
a6f1e3d82f
|
@ -226,16 +226,17 @@ class Config(object):
|
||||||
if self.option.tracedir is not None:
|
if self.option.tracedir is not None:
|
||||||
return py.path.local(self.option.tracedir)
|
return py.path.local(self.option.tracedir)
|
||||||
|
|
||||||
def maketrace(self, name, flush=False):
|
def maketrace(self, name, flush=True):
|
||||||
""" return a tracedirectory or None, depending on --tracedir. """
|
""" return a tracedirectory or None, depending on --tracedir. """
|
||||||
tracedir = self.gettracedir()
|
tracedir = self.gettracedir()
|
||||||
if tracedir is None:
|
if tracedir is None:
|
||||||
return NullTracer()
|
return NullTracer()
|
||||||
|
tracedir.ensure(dir=1)
|
||||||
return Tracer(tracedir.join(name), flush=flush)
|
return Tracer(tracedir.join(name), flush=flush)
|
||||||
|
|
||||||
class Tracer(object):
|
class Tracer(object):
|
||||||
file = None
|
file = None
|
||||||
def __init__(self, path, flush=False):
|
def __init__(self, path, flush=True):
|
||||||
self.file = path.open(mode='w')
|
self.file = path.open(mode='w')
|
||||||
self.flush = flush
|
self.flush = flush
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,12 @@ class TestSessionAndOptions:
|
||||||
assert s.find("TestrunStart") != -1
|
assert s.find("TestrunStart") != -1
|
||||||
|
|
||||||
def test_tracedir_tracer(self):
|
def test_tracedir_tracer(self):
|
||||||
tracedir = self.tmpdir.mkdir("tracedir")
|
tracedir = self.tmpdir.join("tracedir")
|
||||||
config = py.test.config._reparse([self.tmpdir,
|
config = py.test.config._reparse([self.tmpdir,
|
||||||
'--tracedir=%s' % tracedir])
|
'--tracedir=%s' % tracedir])
|
||||||
assert config.gettracedir() == tracedir
|
assert config.gettracedir() == tracedir
|
||||||
|
|
||||||
trace = config.maketrace("trace1.log", flush=True)
|
trace = config.maketrace("trace1.log") # flush=True by default
|
||||||
trace("hello", "world")
|
trace("hello", "world")
|
||||||
class A: pass
|
class A: pass
|
||||||
trace(A())
|
trace(A())
|
||||||
|
|
Loading…
Reference in New Issue