addresses issue #22

allow test functions to have no func_code

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-06-24 15:55:57 +02:00
parent 7602096f81
commit f531a1d6c9
2 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,9 @@ Changes between 1.0.0b3 and 1.0.0
* perform setup finalization before reporting failures
* apply modified from Andreas Kloeckner to allow
test functions to have no func_code
Changes between 1.0.0b1 and 1.0.0b3
=============================================

View File

@ -133,11 +133,11 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
res = self._deprecated_join(name)
if res is not None:
return res
if obj.func_code.co_flags & 32: # generator function
if is_generator(obj):
# XXX deprecation warning
return self.Generator(name, parent=self)
else:
return self._genfunctions(name, obj)
else:
return self._genfunctions(name, obj)
def _genfunctions(self, name, funcobj):
module = self.getparent(Module).obj
@ -152,6 +152,12 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
return self.Function(name, parent=self)
return funcargs.FunctionCollector(name=name,
parent=self, calls=metafunc._calls)
def is_generator(func):
try:
return (func.func_code.co_flags & 32) # generator function
except AttributeError: # c / builtin functions have no func_code
return False
class Module(py.test.collect.File, PyCollectorMixin):
def _getobj(self):