[svn r63584] killing more code, simplifying running of tests.

--HG--
branch : trunk
This commit is contained in:
hpk 2009-04-03 22:16:02 +02:00
parent cca19f1183
commit 79793d50e2
2 changed files with 43 additions and 65 deletions

View File

@ -67,13 +67,12 @@ class CollectionReport(BaseReport):
""" Collection Report. """
skipped = failed = passed = False
def __init__(self, colitem, result, excinfo=None, when=None, outerr=None):
def __init__(self, colitem, result, excinfo=None, outerr=None):
self.colitem = colitem
if not excinfo:
self.passed = True
self.result = result
else:
self.when = when
self.outerr = outerr
self.longrepr = self.colitem._repr_failure_py(excinfo, outerr)
if excinfo.errisinstance(Skipped):

View File

@ -25,70 +25,49 @@ class RobustRun(object):
return "<%s colitem=%s>" %(self.__class__.__name__, self.colitem)
class ItemRunner(RobustRun):
def run(self):
""" return result of running setup, execution, teardown procedures. """
excinfo = None
capture = self.getcapture()
try:
try:
when = "setup"
self.colitem.config._setupstate.prepare(self.colitem)
try:
when = "execute"
res = self.colitem.runtest()
finally:
when = "teardown"
self.colitem.config._setupstate.teardown_exact(self.colitem)
when = "execute"
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
raise
except:
excinfo = py.code.ExceptionInfo()
return self.makereport(when, excinfo, outerr)
def makereport(self, when, excinfo, outerr):
testrep = self.colitem.config.pytestplugins.call_firstresult(
"pytest_item_makereport", item=self.colitem,
excinfo=excinfo, when=when, outerr=outerr)
if self.pdb and testrep.failed:
tw = py.io.TerminalWriter()
testrep.toterminal(tw)
self.pdb(excinfo)
return testrep
class CollectorRunner(RobustRun):
def run(self):
""" return result of running setup, execution, teardown procedures. """
excinfo = None
res = NORESULT
capture = self.getcapture()
try:
try:
res = self.colitem._memocollect()
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
raise
except:
excinfo = py.code.ExceptionInfo()
return self.makereport(res, "execute", excinfo, outerr)
def makereport(self, res, when, excinfo, outerr):
return event.CollectionReport(self.colitem, res, excinfo, when, outerr)
NORESULT = object()
#
# public entrypoints / objects
#
def basic_collect_report(item):
return CollectorRunner(item).run()
def basic_run_report(item, pdb=None):
return ItemRunner(item, pdb=pdb).run()
""" return report about setting up and running a test item. """
excinfo = None
capture = item.config._getcapture()
try:
try:
when = "setup"
item.config._setupstate.prepare(item)
try:
when = "execute"
res = item.runtest()
finally:
when = "teardown"
item.config._setupstate.teardown_exact(item)
when = "execute"
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
raise
except:
excinfo = py.code.ExceptionInfo()
testrep = item.config.pytestplugins.call_firstresult(
"pytest_item_makereport", item=item,
excinfo=excinfo, when=when, outerr=outerr)
if pdb and testrep.failed:
tw = py.io.TerminalWriter()
testrep.toterminal(tw)
pdb(excinfo)
return testrep
def basic_collect_report(collector):
excinfo = res = None
try:
capture = collector.config._getcapture()
try:
res = collector._memocollect()
finally:
outerr = capture.reset()
except (Exit, KeyboardInterrupt):
raise
except:
excinfo = py.code.ExceptionInfo()
return event.CollectionReport(collector, res, excinfo, outerr)
from cPickle import Pickler, Unpickler
from cStringIO import StringIO