From 3630e7fcd3fcb1493867518b5dfcde6c12aaa605 Mon Sep 17 00:00:00 2001 From: fijal Date: Tue, 30 Jan 2007 17:59:32 +0100 Subject: [PATCH] [svn r37624] Slightly hackish way to put all tracing calls as low as possible. This should kill unnecessary frames. Right now tracing is done only for py.test.Function objects, I don't know what to do with sth else, let's leave it alone. --HG-- branch : trunk --- py/test/rsession/executor.py | 32 ++++++++++++++++++++++++++++++-- py/test/rsession/local.py | 10 ++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/py/test/rsession/executor.py b/py/test/rsession/executor.py index 8c3ff174a..b13606bfb 100644 --- a/py/test/rsession/executor.py +++ b/py/test/rsession/executor.py @@ -18,10 +18,13 @@ class RunExecutor(object): self.reporter = reporter self.config = config assert self.config + + def run(self): + self.item.run() def execute(self): try: - self.item.run() + self.run() outcome = Outcome() except py.test.Item.Skipped, e: outcome = Outcome(skipped=str(e)) @@ -49,8 +52,33 @@ class RunExecutor(object): outcome.stderr = "" return outcome +class ApigenExecutor(RunExecutor): + """ Same as RunExecutor, but takes tracer to trace calls as + an argument to execute + """ + def execute(self, tracer): + self.tracer = tracer + return super(ApigenExecutor, self).execute() + + def wrap_underlaying(self, target): + def f(*args): + try: + self.tracer.start_tracing() + return target(*args) + finally: + self.tracer.end_tracing() + return f + + def run(self): + """ We want to trace *only* function objects here. Unsure + what to do with custom collectors at all + """ + if hasattr(self.item, 'obj') and type(self.item.obj) is py.test.Function: + self.item.obj = self.wrap_underlaying(self.item.obj) + self.item.run() + class BoxExecutor(RunExecutor): - """ Same as run executor, but boxes test instead + """ Same as RunExecutor, but boxes test instead """ wraps = True diff --git a/py/test/rsession/local.py b/py/test/rsession/local.py index 4e9087ed3..0cba0fac9 100644 --- a/py/test/rsession/local.py +++ b/py/test/rsession/local.py @@ -2,7 +2,8 @@ """ local-only operations """ -from py.__.test.rsession.executor import BoxExecutor, RunExecutor +from py.__.test.rsession.executor import BoxExecutor, RunExecutor,\ + ApigenExecutor from py.__.test.rsession import report from py.__.test.rsession.outcome import ReprOutcome @@ -37,13 +38,10 @@ def benchmark_runner(item, session, reporter): raise NotImplementedError() def apigen_runner(item, session, reporter): - r = RunExecutor(item, reporter=reporter, config=session.config) startcapture(session) #retval = plain_runner(item, session, reporter) - r = RunExecutor(item, reporter=reporter, config=session.config) - session.tracer.start_tracing() - outcome = r.execute() - session.tracer.end_tracing() + r = ApigenExecutor(item, reporter=reporter, config=session.config) + outcome = r.execute(session.tracer) outcome = ReprOutcome(outcome.make_repr(session.config.option.tbstyle)) outcome.stdout, outcome.stderr = finishcapture(session) return outcome