[svn r63588] shift running of test item to be done through a plugin method.
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									79793d50e2
								
							
						
					
					
						commit
						db60fe7f37
					
				|  | @ -465,14 +465,8 @@ class Directory(FSCollector): | ||||||
|             return self.config.pytestplugins.call_each( |             return self.config.pytestplugins.call_each( | ||||||
|                 'pytest_collect_directory', path=path, parent=self) |                 'pytest_collect_directory', path=path, parent=self) | ||||||
| 
 | 
 | ||||||
| from py.__.test.runner import basic_run_report, forked_run_report |  | ||||||
| class Item(Node):  | class Item(Node):  | ||||||
|     """ a basic test item. """ |     """ a basic test item. """ | ||||||
|     def _getrunner(self): |  | ||||||
|         if self.config.option.boxed: |  | ||||||
|             return forked_run_report |  | ||||||
|         return basic_run_report |  | ||||||
| 
 |  | ||||||
|     def _deprecated_testexecution(self): |     def _deprecated_testexecution(self): | ||||||
|         if self.__class__.run != Item.run: |         if self.__class__.run != Item.run: | ||||||
|             warnoldtestrun() |             warnoldtestrun() | ||||||
|  |  | ||||||
|  | @ -7,10 +7,9 @@ import py | ||||||
| XSpec = py.execnet.XSpec | XSpec = py.execnet.XSpec | ||||||
| 
 | 
 | ||||||
| def run(item, node): | def run(item, node): | ||||||
|     runner = item._getrunner() |     report = item.config.pytestplugins.do_itemrun(item)  | ||||||
|     rep = runner(item) |     report.node = node  | ||||||
|     rep.node = node |     return report | ||||||
|     return rep |  | ||||||
| 
 | 
 | ||||||
| class MockNode: | class MockNode: | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|  |  | ||||||
|  | @ -132,7 +132,5 @@ class SlaveNode(object): | ||||||
|             raise |             raise | ||||||
| 
 | 
 | ||||||
|     def runtest(self, item): |     def runtest(self, item): | ||||||
|         runner = item._getrunner() |         report = item.config.pytestplugins.do_itemrun(item) | ||||||
|         testrep = runner(item) |         self.sendevent("itemtestreport", report) | ||||||
|         self.sendevent("itemtestreport", testrep) |  | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -36,6 +36,9 @@ class PluginHooks: | ||||||
|     def pytest_pymodule_makeitem(self, modcol, name, obj): |     def pytest_pymodule_makeitem(self, modcol, name, obj): | ||||||
|         """ return custom item/collector for a python object in a module, or None.  """ |         """ 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  |     # runtest related hooks  | ||||||
|     # ------------------------------------------------------------------------------ |     # ------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
|  | @ -3,6 +3,15 @@ import py | ||||||
| class DefaultPlugin: | class DefaultPlugin: | ||||||
|     """ Plugin implementing defaults and general options. """  |     """ 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): |     def pytest_pyfunc_call(self, pyfuncitem, args, kwargs): | ||||||
|         pyfuncitem.obj(*args, **kwargs) |         pyfuncitem.obj(*args, **kwargs) | ||||||
| 
 | 
 | ||||||
|  | @ -14,7 +23,7 @@ class DefaultPlugin: | ||||||
|             if ext == ".py": |             if ext == ".py": | ||||||
|                 return parent.Module(path, parent=parent)  |                 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) |         #excludelist = parent._config.getvalue_pathlist('dir_exclude', path) | ||||||
|         #if excludelist and path in excludelist: |         #if excludelist and path in excludelist: | ||||||
|         #    return  |         #    return  | ||||||
|  | @ -24,7 +33,11 @@ class DefaultPlugin: | ||||||
|                 if path == arg or arg.relto(path): |                 if path == arg or arg.relto(path): | ||||||
|                     break |                     break | ||||||
|             else: |             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  |         # not use parent.Directory here as we generally  | ||||||
|         # want dir/conftest.py to be able to  |         # want dir/conftest.py to be able to  | ||||||
|         # define Directory(dir) already  |         # define Directory(dir) already  | ||||||
|  |  | ||||||
|  | @ -105,6 +105,9 @@ class PytestPlugins(object): | ||||||
|         self.pyplugins.call_each("pytest_unconfigure", config=config) |         self.pyplugins.call_each("pytest_unconfigure", config=config) | ||||||
|         config.bus.unregister(self) |         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 | #  XXX old code to automatically load classes | ||||||
| # | # | ||||||
|  |  | ||||||
|  | @ -133,7 +133,6 @@ class Session(object): | ||||||
|         post_mortem(excinfo._excinfo[2]) |         post_mortem(excinfo._excinfo[2]) | ||||||
| 
 | 
 | ||||||
|     def runtest(self, item): |     def runtest(self, item): | ||||||
|         runner = item._getrunner() |  | ||||||
|         pdb = self.config.option.usepdb and self.runpdb or None |         pdb = self.config.option.usepdb and self.runpdb or None | ||||||
|         testrep = runner(item, pdb=pdb)  |         report = item.config.pytestplugins.do_itemrun(item, pdb=pdb) | ||||||
|         self.bus.notify("itemtestreport", testrep) |         self.bus.notify("itemtestreport", report)  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue