cleanup: move creation of python colitems to a default pytest_pycollect_makeitem hook impl

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-21 18:42:40 +02:00
parent 9910db2ca6
commit 118eebb190
3 changed files with 30 additions and 25 deletions

View File

@ -119,3 +119,31 @@ def setsession(config):
elif val("dist") != "no":
from _py.test.dist.dsession import DSession
config.setsessionclass(DSession)
# pycollect related hooks and code, should move to pytest_pycollect.py
def pytest_pycollect_makeitem(__multicall__, collector, name, obj):
res = __multicall__.execute()
if res is not None:
return res
if collector._istestclasscandidate(name, obj):
res = collector._deprecated_join(name)
if res is not None:
return res
return collector.Class(name, parent=collector)
elif collector.funcnamefilter(name) and hasattr(obj, '__call__'):
res = collector._deprecated_join(name)
if res is not None:
return res
if is_generator(obj):
# XXX deprecation warning
return collector.Generator(name, parent=collector)
else:
return collector._genfunctions(name, obj)
def is_generator(func):
try:
return py.code.getrawcode(func).co_flags & 32 # generator function
except AttributeError: # builtin functions have no bytecode
# assume them to not be generators
return False

View File

@ -18,7 +18,7 @@ import sys
def pytest_pycollect_makeitem(collector, name, obj):
if 'unittest' not in sys.modules:
return # nobody could have possibly derived a subclass
return # nobody derived unittest.TestCase
try:
isunit = issubclass(obj, py.std.unittest.TestCase)
except TypeError:

View File

@ -120,24 +120,8 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
return self.join(name)
def makeitem(self, name, obj):
res = self.config.hook.pytest_pycollect_makeitem(
return self.config.hook.pytest_pycollect_makeitem(
collector=self, name=name, obj=obj)
if res is not None:
return res
if self._istestclasscandidate(name, obj):
res = self._deprecated_join(name)
if res is not None:
return res
return self.Class(name, parent=self)
elif self.funcnamefilter(name) and hasattr(obj, '__call__'):
res = self._deprecated_join(name)
if res is not None:
return res
if is_generator(obj):
# XXX deprecation warning
return self.Generator(name, parent=self)
else:
return self._genfunctions(name, obj)
def _istestclasscandidate(self, name, obj):
if self.classnamefilter(name) and \
@ -146,7 +130,6 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
# XXX WARN
return False
return True
def _genfunctions(self, name, funcobj):
module = self.getparent(Module).obj
@ -162,12 +145,6 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
return funcargs.FunctionCollector(name=name,
parent=self, calls=metafunc._calls)
def is_generator(func):
try:
return py.code.getrawcode(func).co_flags & 32 # generator function
except AttributeError: # builtin functions have no bytecode
# assume them to not be generators
return False
class Module(py.test.collect.File, PyCollectorMixin):
def _getobj(self):