[py-svn] r56789 - in py/branch/event/py/test2: . testing
hpk at codespeak.net
hpk at codespeak.net
Fri Jul 25 18:11:02 CEST 2008
Author: hpk
Date: Fri Jul 25 18:11:01 2008
New Revision: 56789
Modified:
py/branch/event/py/test2/item.py
py/branch/event/py/test2/runner.py
py/branch/event/py/test2/session.py
py/branch/event/py/test2/testing/test_runner.py
Log:
refactor and add pdb operations to the runner
Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py (original)
+++ py/branch/event/py/test2/item.py Fri Jul 25 18:11:01 2008
@@ -1,6 +1,6 @@
import py
from py.__.test2.collect import FunctionMixin, Node
-from py.__.test2.runner import basic_runner, fork_runner
+from py.__.test2.runner import basic_run_report, forked_run_report
from py.__.test2 import pypresent
_dummy = object()
@@ -52,9 +52,9 @@
def _getrunner(self):
if self._config.option.boxed:
- return fork_runner
- return basic_runner
-
+ return forked_run_report
+ return basic_run_report
+
class Function(FunctionMixin, Item):
""" a Function Item is responsible for setting up
and executing a Python callable test object.
Modified: py/branch/event/py/test2/runner.py
==============================================================================
--- py/branch/event/py/test2/runner.py (original)
+++ py/branch/event/py/test2/runner.py Fri Jul 25 18:11:01 2008
@@ -21,8 +21,8 @@
self.excinfo = excinfo
self.outerr = outerr
-def basic_runner(item, setupstate, getcapture):
- """ returns a RunInfo object after having run the given test items. """
+def setup_and_execute(item, setupstate, getcapture):
+ """ returns RunInfo after setup and execution of test item. """
capture = getcapture()
excinfo = None
try:
@@ -42,8 +42,7 @@
raise
except:
excinfo = py.code.ExceptionInfo()
- runinfo = RunInfo(item, outcome, excinfo, outerr)
- return makereport(runinfo)
+ return RunInfo(item, outcome, excinfo, outerr)
def makereport(runinfo):
item = runinfo.item
@@ -56,14 +55,21 @@
title="failure during setup/teardown")
return repevent.ItemTestReport(trail, runinfo.outcome, repr_run, repr_path)
-def fork_runner(item, setupstate, getcapture):
+def basic_run_report(item, setupstate, getcapture, pdb=None):
+ runinfo = setup_and_execute(item, setupstate, getcapture)
+ if pdb is not None and runinfo.outcome in ('failed', 'setupfailed'):
+ pdb(runinfo)
+ return makereport(runinfo)
+
+def forked_run_report(item, setupstate, getcapture, pdb=None):
EXITSTATUS_TESTEXIT = 4
def runforked():
try:
- testrep = basic_runner(item, setupstate, getcapture)
+ runinfo = setup_and_execute(item, setupstate, getcapture)
except (KeyboardInterrupt, Exit):
os._exit(EXITSTATUS_TESTEXIT)
+ testrep = makereport(runinfo)
return testrep.dumps()
ff = py.io.ForkedFunc(runforked)
Modified: py/branch/event/py/test2/session.py
==============================================================================
--- py/branch/event/py/test2/session.py (original)
+++ py/branch/event/py/test2/session.py Fri Jul 25 18:11:01 2008
@@ -86,4 +86,3 @@
def runtest(self, item):
runner = item._getrunner()
return runner(item, item._config._setupstate, item._config._getcapture)
-
Modified: py/branch/event/py/test2/testing/test_runner.py
==============================================================================
--- py/branch/event/py/test2/testing/test_runner.py (original)
+++ py/branch/event/py/test2/testing/test_runner.py Fri Jul 25 18:11:01 2008
@@ -39,12 +39,12 @@
pass
class RunnerTests:
- def run(self, func, setupstate=None, getcapture=None):
+ def run(self, func, setupstate=None, getcapture=None, pdb=None):
runner = self.getrunner()
item = MockItem(func)
if not setupstate: setupstate = MockSetupState()
if not getcapture: getcapture = MockCapture
- testrep = runner(item, setupstate, getcapture)
+ testrep = runner(item, setupstate, getcapture, pdb=pdb)
return testrep
def test_run_pass(self):
@@ -145,7 +145,7 @@
class TestBasicRunner(RunnerTests):
def getrunner(self):
- return runner.basic_runner
+ return runner.basic_run_report
def test_runner_handles_setupstate(self):
l = []
@@ -193,8 +193,15 @@
assert l[0] == 0
assert l[1].excinfo.errisinstance(ValueError)
- def test_runner_handles_pdb(self):
- py.test.skip("check for proper pdb interaction")
+ def test_invoking_pdb(self):
+ l = []
+ def testfunc():
+ raise ValueError(7)
+ def mypdb(runinfo):
+ l.append(runinfo)
+ testrep = self.run(testfunc, pdb=mypdb)
+ assert len(l) == 1
+ assert l[0].excinfo.exconly().find("ValueError: 7") != -1
class TestForkRunner(RunnerTests):
def setup_class(cls):
@@ -202,7 +209,7 @@
py.test.skip("need os.fork()")
def getrunner(self):
- return runner.fork_runner
+ return runner.forked_run_report
def test_exit_does_bail_out(self):
def testfunc():
More information about the pytest-commit
mailing list