refactor basic_run_report a bit to allow for immediate PDB runs and clearer code.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-22 19:57:11 +02:00
parent b8926f59da
commit def623e289
1 changed files with 27 additions and 21 deletions

View File

@ -9,35 +9,41 @@
import py import py
from py.__.test.outcome import Skipped from py.__.test.outcome import Skipped
from py.__.test.custompdb import post_mortem
class Call:
excinfo = None
def __init__(self, when, func):
self.when = when
try:
self.result = func()
except KeyboardInterrupt:
raise
except:
self.excinfo = py.code.ExceptionInfo()
def runtest_with_deprecated_check(item):
if not item._deprecated_testexecution():
item.runtest()
def basic_run_report(item, pdb=None): def basic_run_report(item, pdb=None):
""" return report about setting up and running a test item. """ """ return report about setting up and running a test item. """
excinfo = None setupstate = item.config._setupstate
capture = item.config._getcapture() capture = item.config._getcapture()
try: try:
try: call = Call("setup", lambda: setupstate.prepare(item))
when = "setup" if not call.excinfo:
item.config._setupstate.prepare(item) call = Call("runtest", lambda: runtest_with_deprecated_check(item))
try: if not call.excinfo:
when = "runtest" call = Call("teardown", lambda: setupstate.teardown_exact(item))
if not item._deprecated_testexecution(): finally:
item.runtest() outerr = capture.reset()
finally:
when = "teardown"
item.config._setupstate.teardown_exact(item)
when = "runtest"
finally:
outerr = capture.reset()
except KeyboardInterrupt:
raise
except:
excinfo = py.code.ExceptionInfo()
testrep = item.config.hook.pytest_item_makereport( testrep = item.config.hook.pytest_item_makereport(
item=item, excinfo=excinfo, when=when, outerr=outerr) item=item, excinfo=call.excinfo, when=call.when, outerr=outerr)
if pdb and testrep.failed: if pdb and testrep.failed:
tw = py.io.TerminalWriter() tw = py.io.TerminalWriter()
testrep.toterminal(tw) testrep.toterminal(tw)
pdb(excinfo) pdb(call.excinfo)
return testrep return testrep
def basic_collect_report(collector): def basic_collect_report(collector):