diff --git a/py/test/collect.py b/py/test/collect.py index 614e8fe2f..7b6c68d14 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -465,14 +465,8 @@ class Directory(FSCollector): return self.config.pytestplugins.call_each( 'pytest_collect_directory', path=path, parent=self) -from py.__.test.runner import basic_run_report, forked_run_report class Item(Node): """ a basic test item. """ - def _getrunner(self): - if self.config.option.boxed: - return forked_run_report - return basic_run_report - def _deprecated_testexecution(self): if self.__class__.run != Item.run: warnoldtestrun() diff --git a/py/test/dist/testing/test_dsession.py b/py/test/dist/testing/test_dsession.py index 8954035ed..1233d1a90 100644 --- a/py/test/dist/testing/test_dsession.py +++ b/py/test/dist/testing/test_dsession.py @@ -7,10 +7,9 @@ import py XSpec = py.execnet.XSpec def run(item, node): - runner = item._getrunner() - rep = runner(item) - rep.node = node - return rep + report = item.config.pytestplugins.do_itemrun(item) + report.node = node + return report class MockNode: def __init__(self): diff --git a/py/test/dist/txnode.py b/py/test/dist/txnode.py index 4caba485c..f536bf27d 100644 --- a/py/test/dist/txnode.py +++ b/py/test/dist/txnode.py @@ -132,7 +132,5 @@ class SlaveNode(object): raise def runtest(self, item): - runner = item._getrunner() - testrep = runner(item) - self.sendevent("itemtestreport", testrep) - + report = item.config.pytestplugins.do_itemrun(item) + self.sendevent("itemtestreport", report) diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index ea2078e97..305878e13 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -36,6 +36,9 @@ class PluginHooks: def pytest_pymodule_makeitem(self, modcol, name, obj): """ return custom item/collector for a python object in a module, or None. """ + def pytest_itemrun(self, item, pdb=None): + """ run given test item and return test report. """ + # ------------------------------------------------------------------------------ # runtest related hooks # ------------------------------------------------------------------------------ diff --git a/py/test/plugin/pytest_default.py b/py/test/plugin/pytest_default.py index c1d1655a4..cf4acea13 100644 --- a/py/test/plugin/pytest_default.py +++ b/py/test/plugin/pytest_default.py @@ -3,6 +3,15 @@ import py class DefaultPlugin: """ Plugin implementing defaults and general options. """ + def pytest_itemrun(self, item, pdb=None): + from py.__.test.runner import basic_run_report, forked_run_report + if item.config.option.boxed: + runner = forked_run_report + else: + runner = basic_run_report + report = runner(item, pdb=pdb) + return report + def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): pyfuncitem.obj(*args, **kwargs) @@ -13,8 +22,8 @@ class DefaultPlugin: path in parent.config.args: if ext == ".py": return parent.Module(path, parent=parent) - - def pytest_collect_directory(self, path, parent): + + def pytest_collect_recurse(self, path, parent): #excludelist = parent._config.getvalue_pathlist('dir_exclude', path) #if excludelist and path in excludelist: # return @@ -24,7 +33,11 @@ class DefaultPlugin: if path == arg or arg.relto(path): break else: - return + return False + return True + + def pytest_collect_directory(self, path, parent): + # XXX reconsider the following comment # not use parent.Directory here as we generally # want dir/conftest.py to be able to # define Directory(dir) already diff --git a/py/test/pytestplugin.py b/py/test/pytestplugin.py index 725479dd4..bf387a425 100644 --- a/py/test/pytestplugin.py +++ b/py/test/pytestplugin.py @@ -105,6 +105,9 @@ class PytestPlugins(object): self.pyplugins.call_each("pytest_unconfigure", config=config) config.bus.unregister(self) + def do_itemrun(self, item, pdb=None): + return self.pyplugins.call_firstresult("pytest_itemrun", item=item, pdb=pdb) + # # XXX old code to automatically load classes # diff --git a/py/test/session.py b/py/test/session.py index 3450e87ad..168bc38e0 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -133,7 +133,6 @@ class Session(object): post_mortem(excinfo._excinfo[2]) def runtest(self, item): - runner = item._getrunner() pdb = self.config.option.usepdb and self.runpdb or None - testrep = runner(item, pdb=pdb) - self.bus.notify("itemtestreport", testrep) + report = item.config.pytestplugins.do_itemrun(item, pdb=pdb) + self.bus.notify("itemtestreport", report)