diff --git a/_py/test/plugin/pytest_default.py b/_py/test/plugin/pytest_default.py index 54240eb6f..6354505a6 100644 --- a/_py/test/plugin/pytest_default.py +++ b/_py/test/plugin/pytest_default.py @@ -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 diff --git a/_py/test/plugin/pytest_unittest.py b/_py/test/plugin/pytest_unittest.py index 3d92ce0c5..7d242f8fa 100644 --- a/_py/test/plugin/pytest_unittest.py +++ b/_py/test/plugin/pytest_unittest.py @@ -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: diff --git a/_py/test/pycollect.py b/_py/test/pycollect.py index c0aff1631..225eaf15c 100644 --- a/_py/test/pycollect.py +++ b/_py/test/pycollect.py @@ -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):