diff --git a/CHANGELOG b/CHANGELOG index 82b6d7f48..6a6d151ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 ============================================= diff --git a/py/test/pycollect.py b/py/test/pycollect.py index eb010f66a..76394a588 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -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):